Search code examples
c#azure-application-insights

Azure Application Insights does not show C# ILogger logs


We're trying to get Application Insights enabled for our ASP Net Core 7.0 C# application. We've used a few sources, including this Microsoft site:

https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger?WT.mc_id=DOP-MVP-5001942&tabs=dotnet6

The Azure Application Insights module itself seem correctly configured, for example it's showing app requests correctly.

However our custom ILogger messages in our C# application don't show up in the Azure App Insights traces section.

We've based our setup below from various other examples on how to configure ILogging, so we're not sure which aspect of our setup is wrong, but suspect it's in our code somewhere.

C# Program

    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        ...
        
        builder.Services.AddApplicationInsightsTelemetry();

        builder.Logging.AddApplicationInsights(
            configureTelemetryConfiguration: config =>
                 config.ConnectionString = configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"],
            configureApplicationInsightsLoggerOptions: options => { }
        );
        
        ... 

        var app = builder.Build();
    }        

appsettings.json

Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning",
      "ApplicationInsights": "Debug"
    }
  }

csproj file

  <ItemGroup>
    ...
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
    ...
  </ItemGroup>

Azure Web App Settings Configuration

enter image description here


Solution

  • Is there anything in the config below that looks incorrect?

    Yes, the config is wrong, take a look at the right way by examining the following configuration:

    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft.AspNetCore": "Warning"
        },
        "ApplicationInsights": {
          "LogLevel": {
            "Default": "Debug"
          }
        }
      }
    }
    

    As you can see the ApplicationInsights loglevel is set in a subsection.