Search code examples
c#azure-functionsserilog

Getting error when upgrading from Serilog.Sinks.ApplicationInsights v3.1 to v4.0


I have an Azure Function that uses Serilog to write to AppInsights with Serilog AppInsights sink v3.1.

The code in Startup.cs looks like this

Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(config)
            .CreateLogger();

and appsettings.json

"Serilog": {
    "Using": [
      "Serilog.Sinks.ApplicationInsights"
    ],
    "WriteTo": [
      {
        "Name": "ApplicationInsights",
        "Args": {
          "instrumentationKey": "...",
          "restrictedToMinimumLevel": "Verbose",
          "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights"
      }
    }
  ],
  ...

It can happily write application logs into AppInsights.

The latest Github documentation mentioned the deprecation of telemetry configuration active and future removal support of Instrumentation Key therefore I would like to upgrade the library to version 4.0.

However, when I upgrade to the sink to v4.0, I get this exception:

enter image description here

Please help.


Solution

  • So I just spent a good chunk of time debugging this, because I also ran into the issue. I'll admit I should have look at the git log for the app insights sink, because the offending commit is right here

    https://github.com/serilog-contrib/serilog-sinks-applicationinsights/commit/8e4e26a8fdfa12da6ed15afcc94889e5f399ff97#diff-bc9f0e00aaa0aef88484faa764a62f13d26f07bf6c2b6df21cd8d893aa47c2e0

    They adjusted their namespaces, which causes the Serilog Configuration binding not to be able to find the type Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter anymore. Instead the namespace is Serilog.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter as shown in the commit I linked.

    Hope this helps