From 9edd95d3eb3006a1f979c3bba6757c6444bb30e6 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 26 Sep 2020 08:59:22 -0500 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(logging):=20=F0=9F=90=9B=20rollba?= =?UTF-8?q?ck=20logging=20to=20previous=20working=20state"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8126a489ac601c8b7a9e2424120955e42fd84f14. --- .../ConfigurationBuilder.cs | 10 +--------- .../ConfigurationExtensions.cs | 14 +++++++------- .../FilterLists.SharedKernel.Logging.csproj | 3 ++- .../FilterLists.SharedKernel.Logging/HostRunner.cs | 13 ++++++++----- 4 files changed, 18 insertions(+), 22 deletions(-) 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) {