Reputation: 2510
I've spent the entire last day trying to find something to explain why I'm not seeing any Trace, Debug or Information messages in app insights when I run my WorkerService in Azure. The WorkerService is being hosted in a Linux (Ubuntu 18.4) VM in our enterprise space and in all other ways works fine.
The Critical, Error and Warning messages are getting through so the connection is correctly established but something appears to be filtering the messages at the process end.
The relevant logging part of the appsettings.json is as follows:
"Logging": {
"LogLevel": {
"Default": "Trace",
"System": "Trace",
"Microsoft": "Trace"
}
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Trace",
"System": "Trace",
"Microsoft": "Trace"
}
},
...which should allow everything through I would expect. My test code is...
log.LogTrace("WorkerService: Trace");
log.LogDebug("WorkerService: Debug");
log.LogInformation("WorkerService: Information");
log.LogWarning("WorkerService: Warning");
log.LogError("WorkerService: Error");
log.LogCritical("WorkerService: Critical");
...but I have noticed when I run the code locally that the output window shows the following...
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Executing action method MyWorkerService.Features.HealthCheck.HealthCheckController.GetAdvancedHealthCheck (MyWorkerService) - Validation state: Valid
MyWorkerService.Features.HealthCheck.GetAdvancedHealthCheck.Handler: Trace: Trace
MyWorkerService.Features.HealthCheck.GetAdvancedHealthCheck.Handler: Debug: Debug
MyWorkerService.Features.HealthCheck.GetAdvancedHealthCheck.Handler: Information: Information
MyWorkerService.Features.HealthCheck.GetAdvancedHealthCheck.Handler: Warning: Warning
Application Insights Telemetry: {"name":"AppTraces","time":"2020-12-15T08:04:49.6657815Z","iKey":"8d4d3ae1-xxxx-xxxx-xxxx-029e472df754","tags":{"ai.application.ver":"1.0.0.0" ...<snip>... "TraceId":"520378xxxxxxxxxxxxxxxxxxxxe5a1b5"}}}}
MyWorkerService.Features.HealthCheck.GetAdvancedHealthCheck.Handler: Error: Error
Application Insights Telemetry: {"name":"AppTraces","time":"2020-12-15T08:04:49.6688389Z","iKey":"8d4d3ae1-xxxx-xxxx-xxxx-029e472df754","tags":{"ai.application.ver":"1.0.0.0" ...<snip>... "TraceId":"520378xxxxxxxxxxxxxxxxxxxxe5a1b5"}}}}
MyWorkerService.Features.HealthCheck.GetAdvancedHealthCheck.Handler: Critical: Critical
Application Insights Telemetry: {"name":"AppTraces","time":"2020-12-15T08:04:49.6854384Z","iKey":"8d4d3ae1-xxxx-xxxx-xxxx-029e472df754","tags":{"ai.application.ver":"1.0.0.0" ...<snip>... "TraceId":"520378xxxxxxxxxxxxxxxxxxxxe5a1b5"}}}}
...which also suggests that the Trace, Debug and Information messages are not being sent to Azure.
I'm using the "Microsoft.ApplicationInsights.WorkerService" Version="2.16.0" nuget package but cannot see what else I need to configure to change the filter which is limiting the transmitted data.
Any help or suggestions gratefully accepted.
Upvotes: 1
Views: 1687
Reputation: 30035
For appsettings.json
, please make sure you have set the property copy to output directory
as copy if newer
(in visual studio, right click appsettings.json -> select properties).
And then put the ApplicationInsights
section into Logging
section. Like below:
{
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Trace",
"Microsoft.Hosting.Lifetime": "Trace"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Trace",
"System": "Trace",
"Microsoft": "Trace"
}
}
}
}
Here is the test result at my side:
Upvotes: 4