Troubleshooting App Service Logs
This guide helps you understand and troubleshoot issues related to application logs generated by Azure App Service.
Understanding App Service Log Types
Azure App Service provides several types of logs that can be invaluable for diagnosing application and platform issues. The primary log types include:
- Application Logs: Logs generated by your application code. These can include custom logs, trace statements, or error messages.
- Web Server Logs: Logs generated by the underlying web server (e.g., IIS for Windows, Nginx/Apache for Linux) that handles incoming requests.
- Detailed Error Messages: Provides detailed error information for failed HTTP requests (status codes 400 and above).
- Failed Request Tracing: Captures detailed tracing information for failed requests, helping to pinpoint the cause of HTTP errors.
Enabling and Configuring Logs
Before you can troubleshoot, you need to ensure logging is enabled and configured appropriately. You can manage these settings through the Azure portal.
Application Logging
To enable application logging:
- Navigate to your App Service in the Azure portal.
- In the left-hand menu, under "Monitoring," select "App Service logs."
- Under "Application Logging," choose "On."
- Select the "Level" to log (e.g., Error, Warning, Information, Verbose). Verbose captures the most detail but can impact performance.
- Choose a destination for your logs:
- Log stream: View logs in real-time directly in the portal.
- Storage container: Store logs in an Azure Blob Storage container for longer-term retention and analysis.
- Filesystem: Store logs locally within the App Service's file system (limited retention).
Web Server Logging
To enable web server logging:
- In the "App Service logs" section, enable "Web server logging."
- Choose a destination and retention period.
Detailed Error Messages and Failed Request Tracing
These can be enabled similarly in the "App Service logs" section. For Failed Request Tracing, you'll need to configure specific rules.
Accessing and Analyzing Logs
Log Stream
The "Log stream" feature provides a real-time view of your application and web server logs. This is excellent for immediate debugging during development or when actively troubleshooting an issue.
Blob Storage
Storing logs in Blob Storage is the recommended approach for production environments. This allows you to:
- Retain logs for extended periods.
- Use tools like Azure Storage Explorer or custom scripts to download and analyze logs.
- Integrate with log analysis services like Azure Monitor Logs (Log Analytics).
Logs are typically stored in containers named logservices within your storage account. The structure usually involves folders for the App Service name, type of log, and date/time.
Local File System
Logs written to the local file system can be accessed via the Kudu console (https://your-app-name.scm.azurewebsites.net/) under the D:\home\LogFiles directory.
D:\home\LogFiles\
├── Application
│ ├── AppServiceHTTPPlatformHandler.log
│ └── AppServiceHTTPPlatformHandler.trace
├── DetailedErrors
├── eventlog.xml
├── httpPlatformHandler.log
├── npm
├── RecordList
├── Request
│ └── iisnode.log
├── W3SVC1
│ └── u_exYYMMDD.log (Web server logs)
└── WordPress
└── ...
Common Troubleshooting Scenarios
Application Crashes or Unresponsiveness
What to check:
- Enable "Application Logging" at the "Verbose" level.
- Check for unhandled exceptions in application logs.
- Examine web server logs for specific request failures.
- Use "Failed Request Tracing" to get detailed information on requests that timed out or failed.
High CPU or Memory Usage
What to check:
- Monitor application logs for resource-intensive operations or loops.
- Enable detailed logging for any performance profiling tools you might be using.
- Examine web server logs to identify requests that are taking an unusually long time to process.
HTTP Errors (e.g., 500, 404)
What to check:
- Enable "Detailed Error Messages."
- If the issue persists, enable "Failed Request Tracing" and configure rules to capture the specific error codes you are encountering.
- Application logs should indicate any errors occurring within your code during request processing.
Deployment Issues
What to check:
- Review deployment logs in the "Deployment Center" or "Deployment logs" section of the Azure portal.
- If the deployment completes but the application fails, check application logs immediately after deployment.
Best Practices
- Don't log sensitive information: Be mindful of what you log, especially in production environments. Avoid logging passwords, API keys, or PII directly.
- Use appropriate logging levels: Start with "Information" or "Warning" and increase to "Verbose" or "Debug" only when actively troubleshooting.
- Centralize your logs: For production applications, always configure logs to be sent to Azure Blob Storage or integrated with Azure Monitor Logs for robust analysis and retention.
- Set up alerts: Use Azure Monitor to set up alerts based on specific log messages or error patterns.