fix(logging): 🐛 try fix logging via alt AppInishgts config

This commit is contained in:
Collin M. Barrett 2020-09-24 18:51:53 -05:00
parent 47da43e29f
commit 04b268eba0
3 changed files with 11 additions and 3 deletions

View file

@ -11,7 +11,6 @@ internal static class ConfigurationBuilder
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.ApplicationInsights(TelemetryConverter.Traces);
.WriteTo.Console();
}
}

View file

@ -22,6 +22,7 @@
<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

@ -1,5 +1,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
@ -11,7 +13,13 @@ public static async Task TryRunWithLoggingAsync(this IHost host, Func<Task>? run
{
_ = host ?? throw new ArgumentNullException(nameof(host));
Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration.CreateLogger();
Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration
.WriteTo.Conditional(
_ => host.Services.GetService<IHostEnvironment>().IsProduction(),
c => c.ApplicationInsights(
host.Services.GetRequiredService<TelemetryConfiguration>(),
TelemetryConverter.Traces))
.CreateLogger();
try
{