Application diagnostics

This type of logging is used to write application-level logging. It is classified into the following two types of logs:

Application logging (Filesystem)

This is used to log application-level logging on a text file. While configuring, we can set the logging severity level and it logs the error into a text file.

Application logging (Blob)

To log application-level logging on Blob storage, we can set the minimum severity level.

Azure application-level logging can be enabled in ASP.NET Core by adding a package, Microsoft.Extensions.Logging.AzureAppServices, through NuGet, and then calling the AddAzureWebAppDiagnostics method from loggerFactory, as follows:

    public void Configure(IApplicationBuilder app, 
IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddAzureWebAppDiagnostics();
}

AddAzureWebAppDiagnostics also has an overloaded method, which allows you to pass the AzureAppServicesDiagnosticSettings object. This object can be used to override default settings such as the template of logging output, file size, and Blob name. Once this is enabled on the Startup class, we can use the same ILogger object injected in our MVC controllers and log the information. The logs will be generated based on the number of logger providers added.

When we deploy our application on Azure App Service, we can enable Azure logging (text file and Blob) through the diagnostic section. To do that, we will first go to our Azure App, and then search for diagnostic logs.

We can enable text file logging by selecting the On button of Application Logging (Filesystem), as shown in the following screenshot:

Level denotes the minimum severity level for which the logging will be done. Setting this to Verbose logs everything like Verbose, Information, Warning, and Error. However, if the severity is set to Error, it will only log an error, as there is no severity level that exists after error.

The default values of a text file are as follows:

Path /LogFiles/Application folder
File name format diagnostics-yyyymmdd.txt
File size limit 10 MB
Max. number of files retained on Azure 2

Blob table logging can be enabled by selecting the On of Application Logging (Blob) as shown in this screenshot:

In the case of Blob, we can specify the level and configure the Storage Settings. In Storage Settings, we can either select the existing Blob, or create a new one. While creating a new Blob storage you will be prompted for Name, Performance, and Replication, as shown in the following screenshot:

The default values of Blob storage are as follows:

Blob name {appname}{timestamp}/yyyy/mm/dd/hh/{guid}-applicationLog.txt
Azure App Services does not generate any file or Blob entries when the application is running locally and not on Azure.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.142.85