Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serilog configuration via appsettings.json for Application Insights

I am trying to use https://github.com/serilog/serilog-settings-configuration to read app settings and setup serilog for app insights: https://github.com/serilog/serilog-sinks-applicationinsights. The issue I am having is that I cannot set the last parameters for ApplicationInsightsEvents call, which is a function that takes LogEvent and returns ITelemetry. How can this be set via appsettings.json?

Basically, I want to replace the followoing line: log.WriteTo.ApplicationInsightsEvents(instrumentationKey, level, CultureInfo.CurrentCulture, TelemetryConverter.ConvertLogEventsToEnerGovTelemetry);

with a line inside appsettings.json

Thanks.

like image 978
Sergey Barskiy Avatar asked Sep 11 '25 21:09

Sergey Barskiy


1 Answers

Add a sink configuration to appsettings.json

      {
        "Name": "ApplicationInsights",
        "Args": {
          "instrumentationKey": "<instrumentationKey>",
          "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights",
          "outputTemplate": "[{Component}|{MachineName}|{ThreadId}] {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] <{SourceContext}> {Message:lj}{NewLine}{Exception}"
        }
      }

And

"Serilog.Sinks.ApplicationInsights"

to "Serilog:Using" array

like image 200
Denis Derkach Avatar answered Sep 13 '25 17:09

Denis Derkach