Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit b107552

Browse files
Support already configured TelemetryConfiguration for LoggingSetup (#324)
* Support already configured TelemetryConfiguration for LoggingSetup * The MetricTelemetry.Value property is obsolete and replaced by Sum
1 parent f33967c commit b107552

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/NuGet.Services.Logging/LoggingSetup.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,28 @@ public static LoggerConfiguration CreateDefaultLoggerConfiguration(bool withCons
3131

3232
public static ILoggerFactory CreateLoggerFactory(
3333
LoggerConfiguration loggerConfiguration = null,
34-
LogEventLevel applicationInsightsMinimumLogEventLevel = LogEventLevel.Information)
34+
LogEventLevel applicationInsightsMinimumLogEventLevel = LogEventLevel.Information,
35+
TelemetryConfiguration telemetryConfiguration = null)
3536
{
3637
// setup Serilog
3738
if (loggerConfiguration == null)
3839
{
3940
loggerConfiguration = CreateDefaultLoggerConfiguration();
4041
}
4142

42-
if (!string.IsNullOrEmpty(TelemetryConfiguration.Active.InstrumentationKey))
43+
if (telemetryConfiguration != null
44+
&& !string.IsNullOrEmpty(telemetryConfiguration.InstrumentationKey))
4345
{
44-
loggerConfiguration = loggerConfiguration.WriteTo.ApplicationInsightsTraces(
45-
TelemetryConfiguration.Active.InstrumentationKey,
46-
restrictedToMinimumLevel: applicationInsightsMinimumLogEventLevel);
46+
// Even though this method call is marked [Obsolete],
47+
// there's currently no other way to pass in the active TelemetryConfiguration as configured in DI.
48+
// These SeriLog APIs are very likely to change to support passing in the TelemetryConfiguration again.
49+
// See also https://github.com/serilog/serilog-sinks-applicationinsights/issues/121.
50+
51+
#pragma warning disable CS0618 // Type or member is obsolete
52+
loggerConfiguration = loggerConfiguration.WriteTo.ApplicationInsights(
53+
telemetryConfiguration,
54+
applicationInsightsMinimumLogEventLevel);
55+
#pragma warning restore CS0618 // Type or member is obsolete
4756
}
4857

4958
Log.Logger = loggerConfiguration.CreateLogger();

src/NuGet.Services.Logging/TelemetryClientWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void TrackMetric(
5959
{
6060
Timestamp = timestamp,
6161
Name = metricName,
62-
Value = value
62+
Sum = value
6363
};
6464

6565
if (properties != null)

0 commit comments

Comments
 (0)