I have set up a sample WebJob that logs to Application Insights. However, all my exceptions get logged multiple times - two times if I use a timer trigger, three times if I use ServiceBus triggers.
Full code is available here.
My logging configuration:
"Logging": {
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Error"
}
}
},
My code:
var builder = Host.CreateDefaultBuilder(args);
// ...
builder.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
// ...
});
// ...
public async Task MyTimerTriggerOperation([TimerTrigger("0/15 * * * * *", RunOnStartup = true)] TimerInfo timerInfo, CancellationToken cancellationToken)
{
// Do some work...
await Task.Delay(100, cancellationToken);
throw new Exception("test");
}
The exceptions are logged multiple times, both to the console and to Application Insights.
The categories are Host.Results
, Host.Executor
(if using ServiceBus) and the name of my function (Function.MyTimerTriggerOperation
).
I don't want to disable all logs for Host.Results
and Host.Executor
. Do I have other options to limit the number of exceptions in my logs?