Search code examples
azure-application-insights.net-6.0

Ilogger logs are not being sent to application insights


I'm using .NET 6 and I have application insights configured. In my startup I have

    services.AddApplicationInsightsTelemetry();
    services.AddApplicationInsightsKubernetesEnricher();

And in my appsettings I have an instrumentation key configured:

  "ApplicationInsights": {
    "InstrumentationKey": "key"
  }

I also configured the log levels

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  }
}

But when I try to use Ilogger to send custom messages, they are not being sent to application insights.

    logger.LogWarning("Object with id {id} not found.", id);

In my console I see all sorts of AppRequests but none of these contain the error message I put in my Ilogger. What am I missing?


Solution

  • I solved the problem by updating my package(s) to

     <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
     <PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="2.0.1" />