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.AddLogging( builder =>
{
builder.AddApplicationInsights( Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "Microsoft.AspNetCore.Routing.EndpointMiddleware", LogLevel.Information );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker", LogLevel.Information );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "Microsoft.AspNetCore.Hosting.Diagnostics", LogLevel.Error );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "MyApp.ClientAPI.Controllers.AppointmentController", LogLevel.Debug );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "MyApp.ClientAPI", LogLevel.Debug );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "Microsoft", LogLevel.Error );
builder.AddFilter<ApplicationInsightsLoggerProvider>( "", LogLevel.Warning );
builder.AddFilter<ApplicationInsightsLoggerProvider>( null, LogLevel.Warning );
} );
services.AddApplicationInsightsTelemetry( Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] );
I also have the same settings in my appsettings.json:
"Logging":
{
"LogLevel":
{
"Default": "Warning",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Error",
"Microsoft.AspNetCore.Hosting.Diagnostics": "Warning",
"Logging:LogLevel:Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker": "Warning",
"Logging:LogLevel:Microsoft.AspNetCore.Routing.EndpointMiddleware": "Warning",
"MyApp.ClientAPI": "Debug",
"MyApp.ClientAPI.Controllers": "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.
If I try and query the logs in Application Insights to find my exceptions, for example using the query:
// Show logs with warnings or exceptions
// A list of logs which contain warnings or exceptions (latest logs shown first).
FunctionAppLogs
| where Level == "Warning" or Level == "Error"
| project TimeGenerated, HostInstanceId, Level, Message, _ResourceId
| sort by TimeGenerated desc
It just returns an error:
'where' operator: Failed to resolve table or column expression named 'FunctionAppLogs'
How can I create log files that contain debug messages from my code, but only warnings/errors from system code?
I just want to create a log file with my debug output without having to wade through thosands of lines of system debug messages?
