Azure App Service Logging: Monitor Your Web Apps in Real-Time for Windows and Linux
Table of contents
- Steps to Enable App Service Logs and Log Stream for Linux Web Apps
Azure App Service is a fully managed platform for building, deploying, and scaling web apps. It supports multiple operating systems like Windows and Linux and allows you to focus on developing your application rather than managing infrastructure. One crucial feature that Azure offers for web app management is logging. With real-time logging, you can monitor the health, performance, and activity of your web apps, allowing you to identify and troubleshoot issues faster.
In this blog, we will dive into how you can enable, configure, and use Azure App Service logging for both Windows and Linux-based web applications. We will explore the steps for enabling different types of logs, including Application Logs, Web Server Logs, and Diagnostic Logs, and show you how to monitor them in real-time.
Why Is Azure App Service Logging Important? Logging is essential for a variety of reasons:
Troubleshooting: Logs provide detailed information about errors and issues, helping you quickly resolve them. Performance Monitoring: Logs track the performance of your app and help in identifying bottlenecks. Security Auditing: Logs can reveal suspicious activity and unauthorized access attempts, helping with security monitoring. Compliance: Many industries require detailed logs for compliance purposes, and Azure App Service logging ensures you maintain these records.
Steps to Enable App Service Logs and Log Stream for Linux Web Apps
Step 1: Navigate to Your Linux Web App in Azure
Log in to the Azure Portal at portal.azure.com.
In the Search Bar, type the name of your Linux Web App and select it from the search results.
You will now be on your Web App's Overview page.
Step 2: Go to the "App Service Logs" Settings
In the left-hand menu of your Web App’s page, scroll down to the Monitoring section.
Click on App Service Logs under the Monitoring section. This will open the settings page for configuring various logs related to your app.
Step 3: Enable Application Logging (Filesystem)
In the App Service Logs page, locate the Application Logging section.
Toggle the Application Logging option to File System. This enables logging for your application, storing the logs on the server’s file system.
Optionally, configure the Quota (the maximum storage space allocated for logs) and Retention Period (how long the logs will be retained). You can adjust these based on your needs:
Quota: Set the size limit for the log files, e.g., 100MB, 1GB.
Retention Period: Set the number of days for which logs will be retained (e.g., 1 day, 7 days).
Step 4: Save Your Changes
- Once you have configured the application logging settings, click on the Save button at the top of the App Service Logs page.
The changes will take effect immediately, and application logs will start being generated and stored in the file system of your Linux web app.
Step 5: Enable and Use Log Stream
To monitor logs in real-time, you can use the Log Stream feature.
In the Monitoring section of the left-hand menu, click on Log Stream.
You will now be able to view your application logs in real-time as requests and responses occur in your app. This helps you to troubleshoot and monitor the behavior of your application on the go.
Steps to Enable App Service Logs and Log Stream for Windows Web Apps
Step 1: Navigate to Your Windows Web App in Azure
Log in to the Azure Portal at portal.azure.com.
In the Search Bar, type the name of your Windows Web App and select it from the search results.
You will be directed to your Web App’s Overview page.
Step 2: Go to the "App Service Logs" Settings
- In the left-hand menu, under the Monitoring section, click on App Service Logs. This will open the page where you can configure logging settings for your web app.
Step 3: Enable Application Logging (File System)
In the App Service Logs section, locate the Application Logging setting.
Toggle Application Logging to File System. This enables logging for your application and stores the logs in your web app's file system.
Optionally, set the Quota (maximum log file size, e.g., 100MB or 1GB) and Retention Period (how long the logs will be stored, e.g., 1 day, 7 days).
Quota: The log file size limit. Set this based on how much logging data you want to retain before the logs are overwritten.
Retention Period: Choose how many days the logs will be kept (e.g., 7 days).
Step 6: Save Your Changes
After configuring the settings as needed, click the Save button at the top of the page.
These changes will take effect immediately, and your logs will begin to be collected and stored.
Step 7: Enable and Use Log Stream
To monitor logs in real-time, you can use the Log Stream feature.
In the Monitoring section of the left-hand menu, click on Log Stream.
You will now be able to view your application logs in real-time as requests and responses occur in your app. This helps you to troubleshoot and monitor the behavior of your application on the go.
By following these steps, you can easily enable and configure logging for your Windows Web App in Azure, helping you monitor performance, troubleshoot issues, and ensure the health of your application in real time.
Downloading App Service Logs
Once logging is enabled for your Azure App Service, you may want to download the log files to your local machine for offline analysis or to share them with your team. Here's how you can easily do that:
Replace
<yourwebapp>
with the name of your Web App in the following URL:http://<yourwebapp>.scm.azurewebsites.net/api/dump
Open the URL in your browser. This will trigger the download of a dump.zip file.
The dump.zip file contains the LogFiles directory, which holds the logs for your app.
Once downloaded, you can extract the zip file and review the logs stored within the LogFiles folder.
You can enable additional logging options as required. For more details, please refer to Microsoft’s documentation: Enable diagnostics logging for apps in Azure App Service.