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.
- Go to Microsoft Azure portal.
- Navigate to your ASP.NET Core App Service instance.
- Click App Service logsin Monitoringsection:
- Toggle setting Application Logging (Blob) on. As part of this, an extension named ASP.NET Core Logging Integration will be installed.
- Configure logging level. There are four levels that can be configured:
- Error
- Warning
- Information
- Verbose
- Choose Azure blog storage container.
- 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.
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:
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:
- Add package https://www.nuget.org/packages/Microsoft.Extensions.Logging.AzureAppServices to your project.
- In Program.cs, enable Azure Web App Diagnostics:
using Microsoft.Extensions.Logging;
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(builder => builder.AddAzureWebAppDiagnostics())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});