-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Artem Leshchev <[email protected]>
- Loading branch information
Showing
13 changed files
with
115 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<PackageId>Luxoft.Bss.Platform.Logging</PackageId> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.ApplicationInsights" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions"/> | ||
<PackageReference Include="Serilog.AspNetCore" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Bss.Platform.Logging.Sinks; | ||
|
||
using Microsoft.ApplicationInsights; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
using Serilog; | ||
|
||
namespace Bss.Platform.Logging; | ||
|
||
public static class DependencyInjection | ||
{ | ||
public static void AddPlatformLogging(this IHostBuilder builder) => | ||
builder | ||
.UseSerilog( | ||
(context, services, configuration) => | ||
configuration | ||
.ReadFrom.Configuration(context.Configuration) | ||
.ReadFrom.Services(services) | ||
.WriteTo.Sink(new ApplicationInsightsSink(services.GetService<TelemetryClient>())), | ||
true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.ApplicationInsights; | ||
|
||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Bss.Platform.Logging.Sinks; | ||
|
||
public class ApplicationInsightsSink(TelemetryClient? telemetryClient) : ILogEventSink | ||
{ | ||
public void Emit(LogEvent logEvent) | ||
{ | ||
if (telemetryClient is null || logEvent.Exception == null) | ||
{ | ||
return; | ||
} | ||
|
||
telemetryClient.TrackException(logEvent.Exception, logEvent.Properties.ToDictionary(x => x.Key, x => x.Value.ToString())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters