Skip to content

Commit 87d1cde

Browse files
DinoSourcesRexIvan Gavryliuk
authored and
Ivan Gavryliuk
committed
Adding support for using the active TelemetryConfiguration
1 parent 81877a6 commit 87d1cde

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Serilog.Sinks.ApplicationInsights/LoggerConfigurationApplicationInsightsExtensions.cs

+19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ public static LoggerConfiguration ApplicationInsights(
4848
return loggerConfiguration.Sink(new ApplicationInsightsSink(client, telemetryConverter), restrictedToMinimumLevel);
4949
}
5050

51+
/// <summary>
52+
/// Adds a Serilog sink that writes <see cref="LogEvent">log events</see> to Microsoft Application Insights
53+
/// using the active <see cref="TelemetryConfiguration"/>
54+
/// </summary>
55+
/// <param name="loggerConfiguration">The logger configuration.</param>
56+
/// <param name="telemetryConverter">Required telemetry converter.</param>
57+
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
58+
/// <returns></returns>
59+
public static LoggerConfiguration ApplicationInsights(
60+
this LoggerSinkConfiguration loggerConfiguration,
61+
ITelemetryConverter telemetryConverter,
62+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
63+
{
64+
65+
var client = new TelemetryClient(TelemetryConfiguration.Active);
66+
67+
return loggerConfiguration.Sink(new ApplicationInsightsSink(client, telemetryConverter), restrictedToMinimumLevel);
68+
}
69+
5170
/// <summary>
5271
/// Adds a Serilog sink that writes <see cref="LogEvent">log events</see> to Microsoft Application Insights
5372
/// using a custom <see cref="ITelemetry"/> converter / constructor.

0 commit comments

Comments
 (0)