Search code examples
c#azureasp.net-core-mvcazure-web-app-service

How to view log information in Azure Web App


I have developed an ASP.NET Core 6 MVC web app. During development I use loggers at controllers or services like this:

public Result MyService()
{
    _logger.LogInfomation("MyService!");
    // Service's code.
}

However, after deploying to Azure App Service, I cannot find a place to observe these logs. I have tried setting App service logs and looking at Log stream but it doesn't have the information I need.


Solution

  • In the deployed Azure App Service, you can check the logs in Log Stream / Application Insights or even in the KUDU Debug Console.

    • If you want to check the Information logs in Log Stream, configure AddAzureWebAppDiagnostics in Program.cs file.

    • Install the Microsoft.Extensions.Logging.AzureAppServices latest NuGet Package.

    My Program.cs file:

    builder.Services.AddLogging(logs =>
    {
        logs.AddConsole();    
        logs.AddAzureWebAppDiagnostics();
    });
    

    HomeController.cs file:

     public IActionResult Index()
     {
         _logger.LogInformation("MyService!");
         _logger.LogInformation("Logs from Controller");
         return View();
     }
    
    • Along with Application Logging enable the below settings.

    enter image description here

    LogStream:

    enter image description here

    • As already mentioned in comments, enable Application Insights to get the detailed info of the requests/traces.

    Refer my SO Thread to configure Application Insights from Code.