22using Microsoft . ApplicationInsights . Extensibility ;
33using Microsoft . AspNetCore . Http ;
44using Microsoft . Extensions . Configuration ;
5+ using Microsoft . Extensions . DependencyInjection ;
56using Serilog ;
67using Serilog . Events ;
78using Serilog . Formatting . Compact ;
9+ using Serilog . Formatting . Elasticsearch ;
810using System ;
911using System . Collections . Generic ;
1012using System . Linq ;
1113using System . Reflection ;
12- using Serilog . Formatting . Elasticsearch ;
1314
1415namespace Code . Library . AspNetCore . Helpers
1516{
@@ -88,7 +89,7 @@ public static Func<HttpContext, double, Exception, LogEventLevel> GetLevel(LogEv
8889 /// }
8990 /// </remarks>
9091 public static void WithSimpleConfiguration ( this LoggerConfiguration loggerConfig ,
91- IConfiguration configuration )
92+ IConfiguration configuration , IServiceProvider serviceProvider )
9293 {
9394 var name = Assembly . GetEntryAssembly ( ) . GetName ( ) ;
9495
@@ -99,8 +100,7 @@ public static void WithSimpleConfiguration(this LoggerConfiguration loggerConfig
99100 . Enrich . WithProperty ( "Assembly" , $ "{ name . Name } ")
100101 . Enrich . WithProperty ( "Version" , $ "{ name . Version } ")
101102 . Destructure . UsingAttributes ( )
102- // TODO(abhith): find alternative for TelemetryConfiguration.Active
103- . WriteTo . ApplicationInsights ( TelemetryConfiguration . Active , TelemetryConverter . Traces ) ;
103+ . WriteTo . ApplicationInsights ( serviceProvider . GetRequiredService < TelemetryConfiguration > ( ) , TelemetryConverter . Traces ) ;
104104
105105 if ( configuration . GetValue < bool > ( "Serilog:UseElasticsearchFormatter" , false ) )
106106 {
0 commit comments