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

Support already configured TelemetryConfiguration for LoggingSetup #324

Merged
merged 2 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst at it: the MetricTelemetry.Value property is also obsolete and replaced by Sum

};

if (properties != null)
Expand Down