I have application insights connected to my azure functions and use default ILogger for logging.
With default configuration, if you pass an exception in a code such as
log.logError(ex, "Some message")
it will result in both trace entry and an exception entry.
I would like to disable this behavior, so that only unhandled exceptions are captured by AI as an exception entry.
Docs say here (https://docs.microsoft.com/en-us/azure/azure-monitor/app/ilogger) that to achieve that I need setup the AI like this:
builder.AddApplicationInsights(
options => options.TrackExceptionsAsExceptionTelemetry = false);
however it seems it cannot be done in Azure Functions.
For starters I use built-in ILogger support, so I do not explicitly add AI in Startup.cs but even if I did, in the library there is no such method at all but rather builder.Services.AddApplicationInsightsTelemetry
that doesn't have such TrackExceptionsAsExceptionTelemetry property in the options.
I know that a workaround would be to log something like
log.logError($"Some message, {ex.Message}, {ex.StackTrace}")
but maybe there is some better solution?
builder.Services.Configure<ApplicationInsightsLoggerOptions>(o => o.TrackExceptionsAsExceptionTelemetry = false);
in my Startup but it didn't work either – Grzegorz Paluch