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(); 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)