Enable diagnostics logging for Azure App Service from Azure Portal

0 41

Enable application logging

  1. To enable application logging for Windows apps in the Azure portal, navigate to your app and select App Service logs.
  2. Select On for either Application Logging (Filesystem) or Application Logging (Blob), or both.
  3. The Filesystem option is for temporary debugging purposes, and turns itself off in 12 hours. The Blob option is for long-term logging, and needs a blob storage container to write logs to. The Blob option also includes additional information in the log messages, such as the ID of the origin VM instance of the log message (InstanceId), thread ID (Tid), and a more granular timestamp

Enable web server logging

  1. To enable web server logging for Windows apps in the Azure portal, navigate to your app and select App Service logs.
  2. For Web server logging, select Storage to store logs on blob storage, or File System to store logs on the App Service file system.
  3. In Retention Period (Days), set the number of days the logs should be retained.
  4. For logs stored in the App Service file system, the easiest way is to download the ZIP file in the browser at:
    • Linux/container apps: https://<app-name>.scm.azurewebsites.net/api/logs/docker/zip
    • Windows apps: https://<app-name>.scm.azurewebsites.net/api/dump

Log detailed errors

  1. To save the error page or failed request tracing for Windows apps in the Azure portal, navigate to your app and select App Service logs.
  2. Under Detailed Error Logging or Failed Request Tracing, select On, then select Save.

Note: Both types of logs are stored in the App Service file system. Up to 50 errors (files/folders) are retained. When the number of HTML files exceed 50, the oldest 26 errors are automatically deleted.

Add log messages in code

  1. ASP.NET applications can use the System.Diagnostics.Trace class to log information to the application diagnostics log. For example:
    System.Diagnostics.Trace.TraceError("If you're seeing this, something bad happened");
  2. By default, ASP.NET Core uses the Microsoft.Extensions.Logging.AzureAppServices logging provider.

Enable Stream logs

Navigate to your app and select Log stream

Leave A Reply

Your email address will not be published.