From 6dbe07b1861910dbb7f2a2f0cde7700f65972143 Mon Sep 17 00:00:00 2001 From: Xavier Decoster Date: Fri, 6 Dec 2019 13:38:10 +0100 Subject: [PATCH 1/2] Support already configured TelemetryConfiguration for LoggingSetup --- src/NuGet.Services.Logging/LoggingSetup.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/NuGet.Services.Logging/LoggingSetup.cs b/src/NuGet.Services.Logging/LoggingSetup.cs index 9db169d6..387462eb 100644 --- a/src/NuGet.Services.Logging/LoggingSetup.cs +++ b/src/NuGet.Services.Logging/LoggingSetup.cs @@ -31,7 +31,8 @@ public static LoggerConfiguration CreateDefaultLoggerConfiguration(bool withCons public static ILoggerFactory CreateLoggerFactory( LoggerConfiguration loggerConfiguration = null, - LogEventLevel applicationInsightsMinimumLogEventLevel = LogEventLevel.Information) + LogEventLevel applicationInsightsMinimumLogEventLevel = LogEventLevel.Information, + TelemetryConfiguration telemetryConfiguration = null) { // setup Serilog if (loggerConfiguration == null) @@ -39,11 +40,19 @@ public static ILoggerFactory CreateLoggerFactory( loggerConfiguration = CreateDefaultLoggerConfiguration(); } - if (!string.IsNullOrEmpty(TelemetryConfiguration.Active.InstrumentationKey)) + if (telemetryConfiguration != null + && !string.IsNullOrEmpty(telemetryConfiguration.InstrumentationKey)) { - loggerConfiguration = loggerConfiguration.WriteTo.ApplicationInsightsTraces( - TelemetryConfiguration.Active.InstrumentationKey, - restrictedToMinimumLevel: applicationInsightsMinimumLogEventLevel); + // Even though this method call is marked [Obsolete], + // there's currently no other way to pass in the active TelemetryConfiguration as configured in DI. + // These SeriLog APIs are very likely to change to support passing in the TelemetryConfiguration again. + // See also https://github.com/serilog/serilog-sinks-applicationinsights/issues/121. + +#pragma warning disable CS0618 // Type or member is obsolete + loggerConfiguration = loggerConfiguration.WriteTo.ApplicationInsights( + telemetryConfiguration, + applicationInsightsMinimumLogEventLevel); +#pragma warning restore CS0618 // Type or member is obsolete } Log.Logger = loggerConfiguration.CreateLogger(); From 476b2a79ca625fa7a2dc6cdbad556907946f64cb Mon Sep 17 00:00:00 2001 From: Xavier Decoster Date: Fri, 6 Dec 2019 13:46:19 +0100 Subject: [PATCH 2/2] The MetricTelemetry.Value property is obsolete and replaced by Sum --- src/NuGet.Services.Logging/TelemetryClientWrapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NuGet.Services.Logging/TelemetryClientWrapper.cs b/src/NuGet.Services.Logging/TelemetryClientWrapper.cs index 60d40b8c..73b7f70d 100644 --- a/src/NuGet.Services.Logging/TelemetryClientWrapper.cs +++ b/src/NuGet.Services.Logging/TelemetryClientWrapper.cs @@ -59,7 +59,7 @@ public void TrackMetric( { Timestamp = timestamp, Name = metricName, - Value = value + Sum = value }; if (properties != null)