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:
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.
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();
}
Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"ApplicationInsights": "Debug"
}
}
<ItemGroup>
...
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
...
</ItemGroup>
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.