diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationBuilder.cs b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationBuilder.cs index 386902945..ee13d408c 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationBuilder.cs +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationBuilder.cs @@ -1,5 +1,4 @@ -using Microsoft.ApplicationInsights; -using Serilog; +using Serilog; using Serilog.Events; namespace FilterLists.SharedKernel.Logging @@ -13,12 +12,5 @@ internal static class ConfigurationBuilder .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Console(); - - public static LoggerConfiguration WriteToApplicationInsights( - this LoggerConfiguration loggerConfiguration, - TelemetryClient telemetryClient) - { - return loggerConfiguration.WriteTo.ApplicationInsights(telemetryClient, TelemetryConverter.Traces); - } } } diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs index 76ab48a6e..b39ff1ee4 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs @@ -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() - .ServerTelemetryChannelStoragePath - }; - services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel); + //using var serverTelemetryChannel = new ServerTelemetryChannel + //{ + // StorageFolder = configuration.GetSection(ApplicationInsightsOptions.Key) + // .Get() + // .ServerTelemetryChannelStoragePath + //}; + //services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel); services.AddApplicationInsightsTelemetry(); } diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/FilterLists.SharedKernel.Logging.csproj b/services/SharedKernel/FilterLists.SharedKernel.Logging/FilterLists.SharedKernel.Logging.csproj index 2bb27adb3..a1480e1da 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Logging/FilterLists.SharedKernel.Logging.csproj +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/FilterLists.SharedKernel.Logging.csproj @@ -17,11 +17,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/HostRunner.cs b/services/SharedKernel/FilterLists.SharedKernel.Logging/HostRunner.cs index ebf0818bb..d5f30cecf 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Logging/HostRunner.cs +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/HostRunner.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; -using Microsoft.ApplicationInsights; +using Microsoft.ApplicationInsights.Extensibility; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; @@ -8,13 +9,16 @@ namespace FilterLists.SharedKernel.Logging { public static class HostRunner { - public static async Task TryRunWithLoggingAsync(this IHost host, Func? runPreHostAsync = default) + public static async Task TryRunWithLoggingAsync(this IHost host, Func? runPreHostAsync = default) { _ = host ?? throw new ArgumentNullException(nameof(host)); - var telemetryClient = (TelemetryClient)host.Services.GetService(typeof(TelemetryClient)); Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration - .WriteToApplicationInsights(telemetryClient) + .WriteTo.Conditional( + _ => host.Services.GetService().IsProduction(), + c => c.ApplicationInsights( + host.Services.GetRequiredService(), + TelemetryConverter.Traces)) .CreateLogger(); try @@ -27,7 +31,6 @@ public static async Task TryRunWithLoggingAsync(this IHost host, Func Log.Information("Initializing host"); await host.RunAsync(); - return 0; } catch (Exception ex) {