How to View Logs in Azure App Service Easily
To view logs in
Azure App Service, use the Log Stream feature in the Azure Portal for real-time logs or enable Application Logging to save logs to storage. You can also use Azure CLI commands like az webapp log tail to stream logs directly to your terminal.Syntax
Here are common ways to view logs in Azure App Service:
- Azure Portal Log Stream: Navigate to your App Service >
Log streamto see live logs. - Enable Application Logging: Turn on logging in
App Service logssettings to save logs to file system or blob storage. - Azure CLI Command: Use
az webapp log tail --name <app_name> --resource-group <resource_group>to stream logs in terminal.
bash
az webapp log tail --name <app_name> --resource-group <resource_group>Example
This example shows how to stream logs from an Azure App Service using Azure CLI.
bash
az webapp log tail --name myappservice --resource-group myresourcegroupOutput
2024-06-01T12:00:00.000Z INFO Starting log stream...
2024-06-01T12:00:01.000Z INFO HTTP GET /api/values responded 200
2024-06-01T12:00:05.000Z ERROR Exception occurred in processing request
Common Pitfalls
- Not enabling logging in App Service settings before trying to view logs.
- Using
az webapp log tailwithout specifying the correct app name or resource group. - Expecting logs immediately after enabling logging; sometimes it takes a few minutes to start capturing logs.
- Confusing
Log streamwith saved logs; stream shows live logs but does not save them.
bash
Wrong: az webapp log tail --name wrongapp --resource-group wronggroup Right: az webapp log tail --name myappservice --resource-group myresourcegroup
Quick Reference
| Method | Description | How to Access |
|---|---|---|
| Log Stream | View live logs in real-time | Azure Portal > App Service > Log stream |
| Application Logging | Save logs to file system or blob storage | Azure Portal > App Service > App Service logs |
| Azure CLI | Stream logs in terminal | az webapp log tail --name |
Key Takeaways
Enable logging in App Service settings before viewing logs.
Use Azure Portal Log Stream for real-time log viewing.
Use Azure CLI command 'az webapp log tail' to stream logs in terminal.
Logs may take a few minutes to appear after enabling logging.
Ensure correct app name and resource group when using CLI commands.