Asp net core 3 1 logs not showing on azure service log stream

Introduction

ASP.NET is a popular programming language used for building web applications. It provides a framework for developing dynamic websites, web services, and web applications. One common issue that developers face is the logs not showing on the Azure service log stream when ASP.NET Core 3.1. In this article, we will explore this problem and provide a solution with examples.

Problem Description

When deploying an ASP.NET Core 3.1 application to Azure, developers may encounter a situation where the logs are not in the Azure service log stream. This can make it difficult to debug and issues in the application.

Solution

To solve this problem, we need to configure the logging in the ASP.NET Core 3.1 application to send the logs to the Azure service log stream. This can be achieved by modifying the application's configuration settings.

Step 1: Install the Required Packages

First, we need to install the necessary packages to enable logging in the ASP.NET Core 3.1 application. Open the NuGet Manager and run the following :


Install-Package Microsoft.Extensions.Logging.AzureAppServices

Step 2: Configure Logging

Next, we need to configure the logging in the application's startup code. Open the Startup.cs file and add the following code to the ConfigureServices method:


 void ConfigureServices(IServiceCollection services)
{
    // Other configuration code
    
    services.AddLogging(loggingBuilder =>
    {
        loggingBuilder.AddAzureWebAppDiagnostics();
    });
}

This code configures the logging to use the Azure Web App Diagnostics provider, which sends the logs to the Azure service log stream.

Step 3: Enable Logging in Azure

Finally, we need to enable logging in the Azure portal for the deployed application. Follow these steps:

  1. Go to the Azure portal and navigate to the App Service where the ASP.NET Core 3.1 application is deployed.
  2. on “App Service Logs” in the left-hand menu.
  3. Enable the “Application Logging (Filesystem)” and “Web server logging” options.
  4. Save the .

Here is an example of how the logging configuration code should look like in the Startup.cs file:


public void ConfigureServices(IServiceCollection services)
{
    // Other configuration code
    
    services.AddLogging(loggingBuilder =>
    {
        loggingBuilder.AddAzureWebAppDiagnostics();
    });
}

Make sure to replace the “Other configuration code” with your actual application configuration code.

Conclusion

By following the steps outlined in this article, you should be able to solve the issue of logs not showing on the Azure service log stream when using ASP.NET Core 3.1. Configuring the logging to use the Azure Web App Diagnostics provider and enabling logging in the Azure portal will ensure that the logs are visible and help in debugging and troubleshooting your application.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents