Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
/ ServerCommon Public archive

Commit

Permalink
Support already configured TelemetryConfiguration for LoggingSetup (#324
Browse files Browse the repository at this point in the history
)

* Support already configured TelemetryConfiguration for LoggingSetup

* The MetricTelemetry.Value property is obsolete and replaced by Sum
  • Loading branch information
xavierdecoster authored Dec 10, 2019
1 parent f33967c commit b107552
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/NuGet.Services.Logging/LoggingSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,28 @@ 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)
{
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();
Expand Down
2 changes: 1 addition & 1 deletion src/NuGet.Services.Logging/TelemetryClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void TrackMetric(
{
Timestamp = timestamp,
Name = metricName,
Value = value
Sum = value
};

if (properties != null)
Expand Down

0 comments on commit b107552

Please sign in to comment.