Enabling AppServiceAppLogs & AppServiceHTTPLogs diagnostic settings in app services
Published Apr 17 2023 06:58 AM 8,103 Views

Azure provides built-in diagnostics to assist with debugging an App Service app. You can send your logs from your App Service to Storage Accounts, Event Hubs, or Log Analytics.

 

This blog will guide you step-by-step to enable AppServiceHTTPLogs , AppServiceAppLogs and view them in Log Analytics.

 

Step 1:

Go to Azure Portal > App Service > Diagnostic Settings and enable the required settings you would like to send to the destination . In this blog I have taken an example of HTTP Logs and App Service Application Logs in a Windows App Service ( .Net Core ).

 

AmritpalSinghNaroo_4-1681311056514.png

 

You can refer this doc for more details on supported log types.

 

Step 2:

In your application code you can use the usual logging options and send log messages to application logs. By default, ASP.NET Core uses the Microsoft.Extensions.Logging.AzureAppServices logging provider. For more information, see ASP.NET Core logging in Azure.

 

Below is the code snippet of the logging I am doing in my .Net Core MVC webapp.

 

public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            _logger.LogInformation("This is a test to send logs to : Log Analytics Workspace.");

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

 

Step 3:

Go to Azure Portal > Log Analytics workspace > Logs and query the AppServiceAppLogs table and you can see the logs being sent. You can use different levels of logging such as Error, Information, Verbose and etc. in your application and this will show up in your logs in Log Analytics under the “Level” field. You can filter out logs based on the level:

 

AmritpalSinghNaroo_5-1681311131254.png

 

Similarly, you can also query AppServiceHTTPLogs:

 

AmritpalSinghNaroo_6-1681311161831.png

 

Sample Queries in Log Analytics:

 

AppServiceAppLogs

| where TimeGenerated >ago(10m)

 

AppServiceHTTPLogs

| where TimeGenerated >ago(10m)

 

 

More information:

 

If you have any other questions, feel free to comment below!

1 Comment
Version history
Last update:
‎May 10 2023 02:09 AM
Updated by: