refactor(logging): ♻ rm Hosting.Abstractions dep

This commit is contained in:
Collin M. Barrett 2020-09-26 09:02:19 -05:00
parent 9edd95d3eb
commit da0806da59
3 changed files with 12 additions and 15 deletions

View file

@ -21,13 +21,13 @@ public static void AddSharedKernelLogging(this IServiceCollection services, ICon
{
_ = configuration ?? throw new ArgumentNullException(nameof(configuration));
//using var serverTelemetryChannel = new ServerTelemetryChannel
//{
// StorageFolder = configuration.GetSection(ApplicationInsightsOptions.Key)
// .Get<ApplicationInsightsOptions>()
// .ServerTelemetryChannelStoragePath
//};
//services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel);
using var serverTelemetryChannel = new ServerTelemetryChannel
{
StorageFolder = configuration.GetSection(ApplicationInsightsOptions.Key)
.Get<ApplicationInsightsOptions>()
.ServerTelemetryChannelStoragePath
};
services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel);
services.AddApplicationInsightsTelemetry();
}

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
@ -17,12 +17,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.13.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.8" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
</ItemGroup>

View file

@ -14,11 +14,9 @@ public static async Task TryRunWithLoggingAsync(this IHost host, Func<Task>? run
_ = host ?? throw new ArgumentNullException(nameof(host));
Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration
.WriteTo.Conditional(
_ => host.Services.GetService<IHostEnvironment>().IsProduction(),
c => c.ApplicationInsights(
host.Services.GetRequiredService<TelemetryConfiguration>(),
TelemetryConverter.Traces))
.WriteTo.ApplicationInsights(
host.Services.GetRequiredService<TelemetryConfiguration>(),
TelemetryConverter.Traces)
.CreateLogger();
try