1

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?

Alex AIT
  • 17,361
  • 3
  • 36
  • 73
  • To resolve that, you could renew message lock just before it's about to expire using BrokeredMessage.RenewLockAsync(). Please refer [SO Thread](https://stackoverflow.com/a/38768481/16630207). – Harshitha Veeramalla Dec 20 '21 at 09:41
  • @HarshithaVeeramalla-MT What lock is expiring if I throw an exception in a timer trigger? – Alex AIT Dec 20 '21 at 10:24

0 Answers0