1

I am trying to write logs to the Azure application but It's not writing the all logs. There are no errors or exceptions. Please help. I have referred to this document.

I have made the below changes.

Just created the Web API project from VS 2022 targeting to .Net 6.

Added the below line to the default templated code.

builder.Services.AddApplicationInsightsTelemetry();

enter image description here

Added the below to appsettings.json.

  "ApplicationInsights": {
    "ConnectionString": "MyConnectionString"
  }

Added these logs.

_logger.LogInformation("VivekLogInformation");
_logger.LogTrace("VivekLogTrace");
_logger.LogCritical("VivekLogCritical");
_logger.LogDebug("VivekLogDebug");
_logger.LogWarning("VivekLogWarningn");

enter image description here

Run the application and call the action method.

I have tried to run the below query to check the logs.

traces
| where message contains "Vivek"

Note: This is my first time trying to write to application insights.

I am able to see logs by adding these lines. But it only writes VivekLogWarningn and VivekLogCritical in logs. I have tried changing the Default LogLevel to Debug as well. But it's not writing all logs.

builder.Services.AddLogging(builder =>
{
    builder.AddApplicationInsights();
});

I have tried this now.

"Logging": {
  "LogLevel": {
    "Default": "Debug",
    "Microsoft.AspNetCore": "Debug"
  }
}
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • What’s the log level configuration in your app settings file? – Gaurav Mantri Apr 12 '23 at 12:41
  • @GauravMantri added to the question at the end, please check now – Vivek Nuna Apr 12 '23 at 12:42
  • 1
    Annoyingly, Application Insights has its own log subsection inside the `Logging` section - it ignores the default logging section https://stackoverflow.com/a/61637732/314291 Take especial note of the nesting: `Logging->ApplicationInsights->LogLevel -> ...` – StuartLC Apr 12 '23 at 13:17
  • 1
    @StuartLC It looks like you are right. I am able to see the logs now. – Vivek Nuna Apr 12 '23 at 13:28

1 Answers1

0

I had some problems too when I tried to use Application Insights. Check out this StackOverFlow to see if you can find anything usefull - link

Note

Note that this is using Ilogger to log with Application Insights