I have configured App Insights on a .NET 6 project that is in production currently, with the code explained below. However, on a development environment hosted on an App Service, I can see a full list of trace logs for a queue worker (service), and for the same service on production, only Error (severity 3) traces appear.
What could be causing such a symptom? Is there some implicit environment handling code to prevent traces appearing on a non-development environment?
As shown below, I do have a QueueTelemetryFilter class which filters for non-success telemetry over a certain time period, but this a) affects telemetry, and b) would be consistent across all environments if it was the cause.
Configuration:
Program.cs
// Add services to the container.
builder.Services.AddApplicationInsightsTelemetry();
builder.Services.AddApplicationInsightsTelemetryProcessor<QueueTelemetryFilter>();
appsettings.Development.json / appsettings.Production.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ApplicationInsights": {
"ConnectionString": "[REDACTED]"
}
}
Usage:
public class SomeQueueProcessor: ISomeQueueProcessor
{
private readonly ILogger<SomeQueueProcessor> logger;
public SomeQueueProcessor(
ILogger<SomeQueueProcessor> logger)
{
this.logger = logger;
}
public async Task HandleQueue(SomeMessage message, CancellationToken cancellationToken)
{
logger.LogInformation("Begin SomeTask", message.Metadata);
// some code
try {
// some more code
catch(SomeException se){
logger.LogError("SomeTask Failed", se.ExceptionMetadata);
}
logger.LogInformation("End SomeTask", message.Metadata);
}
}
As it turns out - we had an incorrectly configured environment, which was registering a duplicate App Insights logger in Serilog.
Since, we've removed any logging for App Insights in Serilog, and just integrate with App Insights directly.