serilog-contrib / serilog-sinks-applicationinsights

A Serilog sink that writes events to Microsoft Azure Application Insights
Apache License 2.0
220 stars 72 forks source link

Application crash after update from version 3.1.0 to 4.0.0 #207

Open TinoMSoft opened 2 years ago

TinoMSoft commented 2 years ago

Description I updated the Serilog.Sinks.ApplicationInsights nuget package from version 3.1.0 to 4.1.0 in my ASP.NET Core 6 app. When I start the app (console or web app), the app crashes during startup with a NullReferenceException. This exception doesn't contains any information why this happend.

I investigate my app Serilog setup in Startup.cs and found out, Serilog.Sinks.ApplicationInsights required the AI connection string and no longer the instrumentation key. But my config had still the instrumentation key only. Microsoft itself reports code warnings to use connection string instead instrumation key. But the app is will work, when I don't do that.

Reproduction The Serilog config in Startup.cs like before. Add this to your appsettings.json { "Serilog": { "Using": [ "Serilog.Sinks.ApplicationInsights" ], "WriteTo": [ { "Name": "ApplicationInsights", "Args": { "instrumentationKey": "#{ApplicationInsightKey}#", "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3} {Application}] {Message:lj} {NewLine}{Exception}", "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights", "restrictedToMinimumLevel": "Warning" } } ] } }

Expected behavior If a downwards compatibility is impossible, then should Serilog.Sinks.ApplicationInsights throw an human readable ConfigurationException or ArgumentException. e.g "The Application Insights configuration string was not set."

Relevant package, tooling and runtime versions

Additional context Add any other context about the problem here.