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:
If you have any other questions, feel free to comment below!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.