AZ-204: Developing Solutions for Microsoft Azure

Configuring Web App Settings

Configuring Diagnostic Logging

Configuring diagnostic logging is crucial for effectively monitoring the health and performance of your applications in Azure App Service. With diagnostic logging enabled, you capture detailed records of your application's behavior, making it easier to troubleshoot issues, analyze performance, and maintain smooth operations. This guide covers the various diagnostic logging types available on different platforms and details how to configure and analyze these logs.

Types of Diagnostic Logs

Diagnostic logs in Azure App Service are categorized based on the type of information they capture. Below is an overview of each logging type and its use case:

Application Logging

Application logging is supported on both Windows and Linux platforms. It records log messages generated by your application code, including informational messages, warnings, and errors encountered during execution. Depending on your web framework (such as .NET, Node.js, Python, or PHP), the structure of these logs can vary. Application logs are essential for understanding application behavior and troubleshooting issues at the code level.

Web Server Logging

Web server logging is available exclusively on Windows and captures raw HTTP request data in the W3C extended log file format. The logs detail every incoming request to the server, including client IP addresses, requested URLs, and HTTP response statuses. This information is vital for analyzing traffic patterns, detecting anomalies, and verifying how the web server manages client requests.

Detailed Error Logging

Also available only on Windows, detailed error logging records copies of HTML error pages that would normally be sent directly to the client upon an error. These logs provide a replica of the user experience during error conditions, allowing developers to reproduce and resolve the underlying issues more effectively.

Failed Request Tracing

Failed request tracing, another Windows-only feature, provides an in-depth breakdown of step-by-step details for requests that failed to process correctly. This diagnostic tool is particularly beneficial for identifying routing errors, timeouts, or other processing issues that affect request completion.

The image is a table describing different types of diagnostic logging, their platforms, and descriptions. It includes application logging, web server logging, detailed error logging, and failed request tracing.

Deployment Logging

Deployment logging is available on both Windows and Linux. It automatically logs the details related to the deployment of your application. For instance, during automated deployments, every repository commit that triggers a deployment to Azure App Service is logged. Although deployment logging settings are not configurable, this feature is essential for quickly identifying issues in the deployment workflow.

Enabling Diagnostic Settings in Azure App Service

Enabling diagnostic logging in Azure App Service is a straightforward process via the Azure Portal. Follow these steps to configure the diagnostic settings and specify the log storage destination:

  1. Open your App Service in the Azure Portal.
  2. Navigate to the Monitoring section and select Diagnostic Settings.
  3. Click on Add Diagnostic Setting.
  4. Provide a descriptive name (e.g., "AZ204DiagConfig").
  5. Select the log types you wish to capture. Options include:
    • HTTP logs
    • App Service console logs
    • Application logs
    • Audit logs
    • IP security logs
    • Platform logs
    • (Currently in preview) Authentication logs
      Additionally, you can capture metrics like CPU utilization, memory utilization, failed requests, and total requests.

Next, choose your log destination. You can send this information to several endpoints:

  • Log Analytics Workspace – a native service for robust log storage and analysis.
  • A Storage Account – ideal for long-term archiving.
  • An Event Hub – for streaming the logs.
  • A Partner Solution – if you are using an integrated third-party monitoring tool.

For this guide, we will use the Log Analytics Workspace as the destination.

The image shows a Microsoft Azure portal page for configuring diagnostic settings, where various log categories and destination details are selected for sending data to a Log Analytics workspace.

After saving the diagnostic settings, allow a few minutes for your App Service to start collecting logs in the Log Analytics Workspace.

Pro Tip

Regularly review and update your diagnostic settings to ensure you capture all necessary data for comprehensive monitoring.

Analyzing Logs with Log Analytics

Once your logs are ingested into Log Analytics, you can query them using the powerful Kusto Query Language (KQL). This capability allows you to dive deep into your data to identify performance issues or anomalous activities.

For example, if you refresh your website and navigate across various pages, HTTP logs will record these activities. Use the sample query below to filter logs for a specific URI stem containing the text "notthere" (simulating a non-existent page to trigger a 404 error):

AppServiceHTTPLogs
| where csUriStem contains "notthere"

After a few minutes, the query will display log entries showing GET requests along with metadata such as client IP, user agent, request URL, and HTTP response status. This data is particularly useful for diagnosing issues like missing pages or suspicious traffic patterns.

To summarize the number of requests by HTTP status code, you can use the following query:

AppServiceHTTPLogs
| summarize count() by ScStatus

This query provides a breakdown of requests by status code, such as the counts for 200, 404, and other responses.

The image shows the Diagnostic settings page for a web app in Microsoft Azure, displaying options for configuring log and metric exports. It includes a list of diagnostic settings and available data types for collection.

The image shows a Microsoft Azure portal interface displaying log analytics for an application, with a table listing HTTP log entries including details like time generated, category, method, and user agent.

The image shows a Microsoft Azure portal interface displaying log analytics for a workspace. It includes a query result table with details such as time generated, category, method, and status.

SEO Insights

Using descriptive and specific query examples in your documentation improves its visibility to search engines. Leverage keywords like "Azure diagnostic logging", "Log Analytics queries", and "Azure App Service monitoring" to enhance SEO performance.

Conclusion

By enabling and reviewing diagnostic logging on Azure App Service, you gain vital insights into your application's performance and can troubleshoot issues more effectively. Separating logs into categories—application logs, web server logs, detailed error logs, failed request tracing, and deployment logs—provides a comprehensive picture of the operational state of your application.

In the subsequent module, we will delve into scaling applications in Azure App Service. Stay tuned for more detailed insights and hands-on examples.

Watch Video

Watch video content

Previous
Configuring Security Certificates