Cam Bruce
Cam Bruce

Reputation: 5689

Linux Azure App Service - Unable to populate AppServiceAppLogs in Log Analytics

I am struggling to populate the Log Analytics AppServiceAppLogs sink with application logging. I have a .NET Core Web Api hosted in a Linux hosted App Service Plan and using the default MS ILogger According to the official documentation, AppServiceAppLogs is supported on .NET Core on Linux, but I simply can't get the additional category in Log Analytics. Here is my existing configuration:

Log Analytics

Log Analytics

appsettings.json
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddAzureWebAppDiagnostics();
builder.Services.Configure<AzureFileLoggerOptions>(options =>
{
    options.FileName = "azure-diagnostics-";
    options.FileSizeLimit = 50 * 1024;
    options.RetainedFileCountLimit = 5;
});
Controller

File System Logs

File System Logs

Upvotes: 1

Views: 681

Answers (1)

Joaqu&#237;n Vano
Joaqu&#237;n Vano

Reputation: 464

Console logs are basically populated from the STDOUT and STDERR and they are mapped to Informational and Error categories.

To send messages to the AppLogs, you can try the following:

"x-ms-applog:informational:base64:base64String" "x-ms-applog:warning:base64:base64String" "x-ms-applog:error:base64:base64String" "x-ms-applog:critical:base64:base64String"

Benefits:

  1. Multi-line logs (useful for callstacks)
  2. Verbosity levels
  3. Independent channel from middlewares.

It works for:

  1. It works for any Linux on App Service offering or custom container image on Linux on App Service using any stack that can write to the stdout (basically every stack can do this).
  2. It works for any custom container image in Windows Containers on App Service using any stack that can write to the stdout (basically every stack can do this).
  3. It works for Tomcat in Windows and Linux out of the box.
  4. It works for JBoss EAP in Linux out of the box.

For more information: https://learn.microsoft.com/en-us/azure/app-service/monitor-app-service-reference#resource-logs

We are in the process of documenting this.

Upvotes: 0

Related Questions