0

I am trying to add custom logs in my c# asp dot net core web api. I am able to find the api calls logs in Azure portal -> application insights -> logs.

But i am not able to find the custom logs i am entering using below code. whats the place to search for them.

public async Task Invoke(HttpContext httpContext)
{
    // First, get the incoming request
    var request = await FormatRequest(httpContext.Request);

    // TODO: Save log to chosen datastore
    _logger.LogInformation('custommessage101');

    // ------
}

In log analytics query editor i used below query but it didnt fetch anything. Is it even the right place(Azure portal -> application insights -> logs) i am looking at ?

requests | search "custommessage101"
Full Stack Brain
  • 455
  • 1
  • 6
  • 19

2 Answers2

1

It may be that when you configured your logger you set the log level higher than information.

The following set the log level so that Information logging will be stored:

builder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("", LogLevel.Information);
Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
0

Messages logged to the ILogger interface end up as traces in application insights. An example query would be:

traces | where message == "custommessage101"

Another option would be the Search:

enter image description here

The default log level for messages to application insights is set to Warning. As Shiraz point out, you need to set it to informational. You can do that using code as shown by Shiraz or by adjusting the appsettings.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information"
      }
    }
  }
}
Peter Bons
  • 26,826
  • 4
  • 50
  • 74