0
votes

I'm setting up a new web app to log via Application Insights. I've installed AI, and am seeing all the expected telemetry (server requests, failed requests, etc.) but not logging sent through ILogger. I've looked through all the similar questions I could find on SO, but none resolved my issue.

I'm using .NET 5 and version 2.17.0 (latest stable) of the Microsoft.ApplicationInsights.AspNetCore nuget package. The connection string and instrumentation key appear correct. I've tried turning on developer mode in TelemetryConfiguration. I'm attempting a log of every level and my code is functionally identical to all the examples I've found.

Startup.cs/ConfigureServices: enter image description here

Controller: enter image description here enter image description here

I set the default LogLevel for ApplicationInsights to "Trace":

enter image description here

The Output window in VS shows that when I log, trace telemetry is being sent:

VS Output window showing AppTraces telemetry

Yet I don't see any logging in Application Insights! I'm absolutely stumped. Any assistance on unraveling this problem would be much appreciated. Thank you!

2
Did you set the logging level in appsettings.json? See this section. - Tiny Wang
@TinyWang Yes, I'll clarify that in the question. Thanks! - Nat Webb
To show my content clearly, I post it as an answer, you could try it, thanks for your response sir : ) - Tiny Wang
Do you see anything in Live Metrics? Or does it show a demo screen? - ZakiMa

2 Answers

0
votes

Since you see data when debugging with VisualStudio, but nothing in the actual ApplicationInsights portal, I'd suggest checking the instrumentation key. It looks like you are passing ConnectionString to the service.AddApplicationInsights() call which is incorrect. That method takes the instrumentation key alone. If you intend to pass the connectionstring, do it like below:

public void ConfigureServices(IServiceCollection services)
{
    var options = new ApplicationInsightsServiceOptions { ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000;" };
    services.AddApplicationInsightsTelemetry(options: options);
}
0
votes

So, it turns out this was a configuration issue inside the Application Insights dashboard. Data Sampling was set to 0%, so nothing was getting through to the logs. To fix this, I went to

Configure -> Usage and estimated costs -> Data sampling

and changed it to 100%.