mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
Revert "fix(logging): 🐛 try yet another AppInsights config"
This reverts commit a313ce9492.
This commit is contained in:
parent
a313ce9492
commit
fee2f0d588
1 changed files with 7 additions and 20 deletions
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
|
|
@ -14,7 +13,13 @@ public static async Task TryRunWithLoggingAsync(this IHost host, Func<Task>? run
|
|||
{
|
||||
_ = host ?? throw new ArgumentNullException(nameof(host));
|
||||
|
||||
InitializeLogger(host);
|
||||
Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration
|
||||
.WriteTo.Conditional(
|
||||
_ => host.Services.GetService<IHostEnvironment>().IsProduction(),
|
||||
c => c.ApplicationInsights(
|
||||
TelemetryConfiguration.CreateDefault(),
|
||||
TelemetryConverter.Traces))
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -37,23 +42,5 @@ public static async Task TryRunWithLoggingAsync(this IHost host, Func<Task>? run
|
|||
Log.CloseAndFlush();
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitializeLogger(IHost host)
|
||||
{
|
||||
var hostEnvironment = host.Services.GetRequiredService<IHostEnvironment>();
|
||||
Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration
|
||||
.ReadFrom.Configuration(host.Services.GetRequiredService<IConfiguration>())
|
||||
.Enrich.WithProperty("Application", hostEnvironment.ApplicationName)
|
||||
.Enrich.WithProperty("Environment", hostEnvironment.EnvironmentName)
|
||||
.WriteTo.Conditional(
|
||||
_ => !hostEnvironment.IsProduction(),
|
||||
sc => sc.Console().WriteTo.Debug())
|
||||
.WriteTo.Conditional(
|
||||
_ => hostEnvironment.IsProduction(),
|
||||
sc => sc.ApplicationInsights(
|
||||
host.Services.GetRequiredService<TelemetryConfiguration>(),
|
||||
TelemetryConverter.Traces))
|
||||
.CreateLogger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue