Configure Azure Blob Storage as Application Log Storage

Raymond Tang Raymond Tang 0 5186 3.16 index 12/22/2020

Azure App Service is a server-less product that can be used to host websites. For ASP.NET core websites, App Service Log feature allows users to configure logging for the web application. This article will show you how to configure Azure Blog Storage container as logging storage for ASP.NET Core web applications.

Config App Service Log

Follow these steps to collect logs and save them to Azure blob storage.

  1. Go to Microsoft Azure portal.
  2. Navigate to your ASP.NET Core App Service instance.
  3. Click App Service logsin Monitoringsection:  2020122252211-image.png
  4. Toggle setting Application Logging (Blob) on. As part of this, an extension named ASP.NET Core Logging Integration will be installed.

 

  1. Configure logging level. There are four levels that can be configured:
    • Error
    • Warning
    • Information
    • Verbose
  2. Choose Azure blog storage container.
  3. Click Save button to save changes.

The following screenshot shows the settings for Kontext platform:

The logs are stored for 180 days in kontexttech storage account's site-logs container.

2020122252521-image.png

View logs in blob storage

Navigate to the blob storage container, you will find the logs are organized in the following folder structure:

Year (2020) > Month (12) > Day (22) > Hour (05) > Application log file.

The following is one example log file generated on Kontext:

2020122253448-image.png

About ASP.NET Core Logging Integration

In the above steps, we utilized the features of Azure App Service to enable logging to Azure blog storage.

You can also directly enable it as part of your ASP.NET Core web application build.

To do this follow these steps:

using Microsoft.Extensions.Logging;

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureLogging(builder => builder.AddAzureWebAppDiagnostics())
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });
asp.net-core azure modern-web-app-on-azure

Join the Discussion

View or add your thoughts below

Comments