3

I am using the provided asp.net core logging and have application insights configured. I can see unhandled exceptions in application insights but I don't see things like logger.LogInformation("testing") anywhere in application insights. I do see the logs in the log stream though.

Additionally I am not seeing logs in the Visual Studio Application Insights screen. I created a hello world app which demonstrates that you don't see the logs in app insights.

https://github.com/devlife/AppInsightsSandbox

Any thoughts?

enter image description here

2

1 Answer 1

4

Can you describe how did you enable ApplicationInsights for capturing ILogger? If you are in the latest beta version of the SDK, ILogger traces are captured without explicit action. But it'll only capture Warning or above level logs.

Follow this doc to configure application insights to capture different log levels. https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger#control-logging-level

If you are not on the latest SDK, then you need to explicitly enable application insights to capture ilogger logs, as per the doc above. Here also you need to configure logging level such that LogInformation is captured.

.ConfigureLogging(
            builder =>
            {                
                builder.AddApplicationInsights("ikey");
  builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("", LogLevel.Information); // this will capture Info level traces and above.
            }
Sign up to request clarification or add additional context in comments.

4 Comments

I updated the question to include a hello world app showing what I did and how it didn't resolve the issue.
In the shared repro, I dont see any code enabling ApplicationInsightsLoggerProvider. Have you followed the instructions in the doc I shared?
It states that is only required if you're using an older SDK. ILogger logs that ApplicationInsightsLoggerProvider captures are subject to the same configuration as any other telemetry that's collected. They have the same set of TelemetryInitializers and TelemetryProcessors, use the same TelemetryChannel, and are correlated and sampled in the same way as other telemetry. If you use version 2.7.0-beta3 or later, no action is required to capture ILogger logs.
You are using 2.6.1 and hence you need to explicitly enable it. Only from 2.7.0-beta3 or higher, its done automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.