I have created an App Service (.NET 5.0) that logs to Application Insights.
The logging is setup in my startup.cs as follows:
public void ConfigureServices( IServiceCollection services )
{
services.AddApplicationInsightsTelemetry( Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] );
services.AddLogging( builder =>
{
builder.AddApplicationInsights( Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "", LogLevel.Warning );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "Microsoft", LogLevel.Error );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "MyApp.ClientAPI", LogLevel.Debug );
} );
I also have the same settings in my appsettings.json:
"Logging":
{
"LogLevel":
{
"Default": "Warning",
"Microsoft": "Error",
"MyApp.ClientAPI": "Debug",
}
}
In the Azure Portal, on the "App Service Logs" page of the App Service, I have Application Logging (Blob) Level set to Verbose.
The log files contain verbose output from everywhere. The above settings are ignored.
I can filter the logs with the following query:
traces
| where operation_Name startswith "POST Appointment/MyWebHook"
| extend category = customDimensions.CategoryName
| where (severityLevel > 1) or (category startswith "MyApp")
| project timestamp, message, severityLevel, category, customDimensions
However, this doesn't prevent huge numbers of Microsoft Trace and Debug messages being stored.
How can I create log files that contain debug messages from my code, but only warnings/errors from system code?
The following is the answer from the link below: (by AnuragSingh-MSFT)
The App Service Logs can't be filtered. To get the application insights filtering working I needed the following settings in my appsettings.json:
"Logging":
{
"ApplicationInsights":
{
"LogLevel":
{
"Default": "Warning",
"Microsoft": "Error",
"MyApp.ClientAPI": "Debug"
}
}
},