@@ -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 ( ) ;
0 commit comments