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 ).
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:
Similarly, you can also query AppServiceHTTPLogs:
Sample Queries in Log Analytics:
AppServiceAppLogs | where TimeGenerated >ago(10m)
AppServiceHTTPLogs | where TimeGenerated >ago(10m) |
More information:
- AppServiceAppLogs is now available for ASP .NET apps on Windows - Azure App Service
- App Service Integration with Azure Monitor (Preview) - Azure App Service
- Enable diagnostics logging - Azure App Service | Microsoft Learn
- Logging in .NET Core and ASP.NET Core | Microsoft Learn
If you have any other questions, feel free to comment below!
Updated May 10, 2023
Version 2.0AmritpalSinghNaroo
Microsoft
Joined March 16, 2022
Apps on Azure Blog
Follow this blog board to get notified when there's new activity