Enable diagnostics logging - Azure App Service (2023)

  • Article
  • 10 minutes to read

Overview

Azure provides built-in diagnostics to assist with debugging an App Service app. In this article, you learn how to enable diagnostic logging and add instrumentation to your application, as well as how to access the information logged by Azure.

This article uses the Azure portal and Azure CLI to work with diagnostic logs. For information on working with diagnostic logs using Visual Studio, see Troubleshooting Azure in Visual Studio.

Note

In addition to the logging instructions in this article, there's new, integrated logging capability with Azure Monitoring. You'll find more on this capability in the Send logs to Azure Monitor section.

TypePlatformLocationDescription
Application loggingWindows, LinuxApp Service file system and/or Azure Storage blobsLogs messages generated by your application code. The messages can be generated by the web framework you choose, or from your application code directly using the standard logging pattern of your language. Each message is assigned one of the following categories: Critical, Error, Warning, Info, Debug, and Trace. You can select how verbose you want the logging to be by setting the severity level when you enable application logging.
Web server loggingWindowsApp Service file system or Azure Storage blobsRaw HTTP request data in the W3C extended log file format. Each log message includes data such as the HTTP method, resource URI, client IP, client port, user agent, response code, and so on.
Detailed Error MessagesWindowsApp Service file systemCopies of the .htm error pages that would have been sent to the client browser. For security reasons, detailed error pages shouldn't be sent to clients in production, but App Service can save the error page each time an application error occurs that has HTTP code 400 or greater. The page may contain information that can help determine why the server returns the error code.
Failed request tracingWindowsApp Service file systemDetailed tracing information on failed requests, including a trace of the IIS components used to process the request and the time taken in each component. It's useful if you want to improve site performance or isolate a specific HTTP error. One folder is generated for each failed request, which contains the XML log file, and the XSL stylesheet to view the log file with.
Deployment loggingWindows, LinuxApp Service file systemLogs for when you publish content to an app. Deployment logging happens automatically and there are no configurable settings for deployment logging. It helps you determine why a deployment failed. For example, if you use a custom deployment script, you might use deployment logging to determine why the script is failing.

Note

App Service provides a dedicated, interactive diagnostics tool to help you troubleshoot your application. For more information, see Azure App Service diagnostics overview.

In addition, you can use other Azure services to improve the logging and monitoring capabilities of your app, such as Azure Monitor.

Enable application logging (Windows)

To enable application logging for Windows apps in the Azure portal, navigate to your app and select App Service logs.

Select On for either Application Logging (Filesystem) or Application Logging (Blob), or both.

The Filesystem option is for temporary debugging purposes, and turns itself off in 12 hours. The Blob option is for long-term logging, and needs a blob storage container to write logs to. The Blob option also includes additional information in the log messages, such as the ID of the origin VM instance of the log message (InstanceId), thread ID (Tid), and a more granular timestamp (EventTickCount).

(Video) How to use Azure Log Monitoring for your .NET Web Apps

Note

If your Azure Storage account is secured by firewall rules, see Networking considerations.

Note

Currently only .NET application logs can be written to the blob storage. Java, PHP, Node.js, Python application logs can only be stored on the App Service file system (without code modifications to write logs to external storage).

Also, if you regenerate your storage account's access keys, you must reset the respective logging configuration to use the updated access keys. To do this:

  1. In the Configure tab, set the respective logging feature to Off. Save your setting.
  2. Enable logging to the storage account blob again. Save your setting.

Select the Level, or the level of details to log. The following table shows the log categories included in each level:

LevelIncluded categories
DisabledNone
ErrorError, Critical
WarningWarning, Error, Critical
InformationInfo, Warning, Error, Critical
VerboseTrace, Debug, Info, Warning, Error, Critical (all categories)

When finished, select Save.

Note

If you write logs to blobs, the retention policy no longer applies if you delete the app but keep the logs in the blobs. For more information, see Costs that might accrue after resource deletion.

Enable application logging (Linux/Container)

To enable application logging for Linux apps or custom containers in the Azure portal, navigate to your app and select App Service logs.

In Application logging, select File System.

(Video) How To Stream Diagnostic Logs For Azure App Service by Accessing The Console Logs From Inside Azure

In Quota (MB), specify the disk quota for the application logs. In Retention Period (Days), set the number of days the logs should be retained.

When finished, select Save.

Enable web server logging

To enable web server logging for Windows apps in the Azure portal, navigate to your app and select App Service logs.

For Web server logging, select Storage to store logs on blob storage, or File System to store logs on the App Service file system.

Note

If your Azure Storage account is secured by firewall rules, see Networking considerations.

In Retention Period (Days), set the number of days the logs should be retained.

Note

If you regenerate your storage account's access keys, you must reset the respective logging configuration to use the updated keys. To do this:

  1. In the Configure tab, set the respective logging feature to Off. Save your setting.
  2. Enable logging to the storage account blob again. Save your setting.

When finished, select Save.

Note

(Video) Logging in Azure App Service(Web App)

If you write logs to blobs, the retention policy no longer applies if you delete the app but keep the logs in the blobs. For more information, see Costs that might accrue after resource deletion.

Log detailed errors

To save the error page or failed request tracing for Windows apps in the Azure portal, navigate to your app and select App Service logs.

Under Detailed Error Logging or Failed Request Tracing, select On, then select Save.

Both types of logs are stored in the App Service file system. Up to 50 errors (files/folders) are retained. When the number of HTML files exceeds 50, the oldest error files are automatically deleted.

The Failed Request Tracing feature by default captures a log of requests that failed with HTTP status codes between 400 and 600. To specify custom rules, you can override the <traceFailedRequests> section in the web.config file.

Add log messages in code

In your application code, you use the usual logging facilities to send log messages to the application logs. For example:

  • ASP.NET applications can use the System.Diagnostics.Trace class to log information to the application diagnostics log. For example:

    System.Diagnostics.Trace.TraceError("If you're seeing this, something bad happened");
  • By default, ASP.NET Core uses the Microsoft.Extensions.Logging.AzureAppServices logging provider. For more information, see ASP.NET Core logging in Azure. For information about WebJobs SDK logging, see Get started with the Azure WebJobs SDK

Stream logs

Before you stream logs in real time, enable the log type that you want. Any information written to the conosle output or files ending in .txt, .log, or .htm that are stored in the /home/LogFiles directory (D:\home\LogFiles) is streamed by App Service.

Note

Some types of logging buffer write to the log file, which can result in out of order events in the stream. For example, an application log entry that occurs when a user visits a page may be displayed in the stream before the corresponding HTTP log entry for the page request.

In Azure portal

To stream logs in the Azure portal, navigate to your app and select Log stream.

In Cloud Shell

To stream logs live in Cloud Shell, use the following command:

(Video) Video 13 Enabling Diagnostics Logging in Azure Web App

Important

This command may not work with web apps hosted in a Linux app service plan.

az webapp log tail --name appname --resource-group myResourceGroup

To filter specific log types, such as HTTP, use the --Provider parameter. For example:

az webapp log tail --name appname --resource-group myResourceGroup --provider http

In local terminal

To stream logs in the local console, install Azure CLI and sign in to your account. Once signed in, followed the instructions for Cloud Shell

Access log files

If you configure the Azure Storage blobs option for a log type, you need a client tool that works with Azure Storage. For more information, see Azure Storage Client Tools.

For logs stored in the App Service file system, the easiest way is to download the ZIP file in the browser at:

  • Linux/custom containers: https://<app-name>.scm.azurewebsites.net/api/logs/docker/zip
  • Windows apps: https://<app-name>.scm.azurewebsites.net/api/dump

For Linux/custom containers, the ZIP file contains console output logs for both the docker host and the docker container. For a scaled-out app, the ZIP file contains one set of logs for each instance. In the App Service file system, these log files are the contents of the /home/LogFiles directory.

For Windows apps, the ZIP file contains the contents of the D:\Home\LogFiles directory in the App Service file system. It has the following structure:

Log typeDirectoryDescription
Application logs/LogFiles/Application/Contains one or more text files. The format of the log messages depends on the logging provider you use.
Failed Request Traces/LogFiles/W3SVC#########/Contains XML files, and an XSL file. You can view the formatted XML files in the browser.
Detailed Error Logs/LogFiles/DetailedErrors/Contains HTM error files. You can view the HTM files in the browser.
Another way to view the failed request traces is to navigate to your app page in the portal. From the left menu, select Diagnose and solve problems, then search for Failed Request Tracing Logs, then click the icon to browse and view the trace you want.
Web Server Logs/LogFiles/http/RawLogs/Contains text files formatted using the W3C extended log file format. This information can be read using a text editor or a utility like Log Parser.
App Service doesn't support the s-computername, s-ip, or cs-version fields.
Deployment logs/LogFiles/Git/ and /deployments/Contain logs generated by the internal deployment processes, as well as logs for Git deployments.

Send logs to Azure Monitor

With the new Azure Monitor integration, you can create Diagnostic Settings to send logs to Storage Accounts, Event Hubs and Log Analytics.

Enable diagnostics logging - Azure App Service (1)

Supported log types

The following table shows the supported log types and descriptions:

Log typeWindowsWindows ContainerLinuxLinux ContainerDescription
AppServiceConsoleLogsJava SE & TomcatYesYesYesStandard output and standard error
AppServiceHTTPLogsYesYesYesYesWeb server logs
AppServiceEnvironmentPlatformLogsYesN/AYesYesApp Service Environment: scaling, configuration changes, and status logs
AppServiceAuditLogsYesYesYesYesLogin activity via FTP and Kudu
AppServiceFileAuditLogsYesYesTBATBAFile changes made to the site content; only available for Premium tier and above
AppServiceAppLogsASP.NET, .NET Core, & Tomcat 1ASP.NET & Tomcat 1.NET Core, Java, SE & Tomcat Blessed Images 2Java SE & Tomcat Blessed Images 2Application logs
AppServiceIPSecAuditLogsYesYesYesYesRequests from IP Rules
AppServicePlatformLogsTBAYesYesYesContainer operation logs
AppServiceAntivirusScanAuditLogs 3YesYesYesYesAnti-virus scan logs using Microsoft Defender for Cloud; only available for Premium tier

1 For Tomcat apps, add TOMCAT_USE_STARTUP_BAT to the app settings and set it to false or 0. Need to be on the latest Tomcat version and use java.util.logging.

2 For Java SE apps, add WEBSITE_AZMON_PREVIEW_ENABLED to the app settings and set it to true or to 1.

(Video) Azure - Application Logging and Crashes, Diagnostics in Windows Azure Web Sites

3 AppServiceAntivirusScanAuditLogs log type is still currently in Preview

Networking considerations

If you secure your Azure Storage account by only allowing selected networks, it can receive logs from App Service only if both of the following are true:

  • The Azure Storage account is in a different Azure region from the App Service app.
  • All outbound addresses of the App Service app are added to the Storage account's firewall rules. To find the outbound addresses for your app, see Find outbound IPs.

Next steps

  • Query logs with Azure Monitor
  • How to Monitor Azure App Service
  • Troubleshooting Azure App Service in Visual Studio
  • Analyze app Logs in HDInsight
  • Tutorial: Run a load test to identify performance bottlenecks in a web app

FAQs

How to enable diagnostics logging for apps in Azure App service? ›

To enable application logging for Windows apps in the Azure portal, navigate to your app and select App Service logs. Select On for either Application Logging (Filesystem) or Application Logging (Blob), or both. The Filesystem option is for temporary debugging purposes, and turns itself off in 12 hours.

Which type of data collection requires you to enable diagnostics in Azure? ›

Rationale: You must enable diagnostics to use Azure Monitor to collect event log data. In addition, you must enable diagnostics to collect other information, such as performance counters and crash logs.

How do I enable diagnostics in Azure? ›

Create or add diagnostic settings for your data factory.
  1. In the Azure portal, navigate to your data factory and select Diagnostics on the left navigation pane to see the diagnostics settings. ...
  2. Give your setting a name, select Send to Log Analytics, and then select a workspace from Log Analytics workspace. ...
  3. Select Save.
Dec 2, 2022

How do you diagnose and solve problems in Azure portal? ›

Open App Service diagnostics

In the left navigation, click on Diagnose and solve problems. For Azure Functions, navigate to your function app, and in the top navigation, click on Platform features, and select Diagnose and solve problems from the Resource management section.

How do I troubleshoot Azure App Service Connection? ›

You can also use the Network troubleshooter to troubleshoot the connection issues for the apps in the App Service. To open the network troubleshooter, go to the app service in the Azure portal. Select Diagnostic and solve problem, and then search for Network troubleshooter.

What are the logs required to diagnostic Azure solution? ›

Azure Diagnostics extension sends data to Azure Storage, Azure Monitor Metrics (Windows only) and Azure Event Hubs. The Log Analytics agent collects data to Azure Monitor Logs. The Log Analytics agent is required for retired solutions, VM insights, and other services such as Microsoft Defender for Cloud.

What is the difference between activity logs and diagnostic logs in Azure? ›

Of important note, the Activity Log is different from Diagnostic Logs. Activity Logs provide data about the operations on a resource from the outside (the “control plane”). Diagnostics Logs are emitted by a resource and provide information about the operation of that resource (the “data plane”).

Which of the following must be specified when enabling diagnostics for an Azure virtual machine? ›

Add the Azure Diagnostics extension to the VM resource definition. To enable the diagnostics extension on a Windows Virtual Machine, you need to add the extension as a VM resource in the Resource Manager template. "name": "[concat(variables('vmName'),'Microsoft.

What is the use of diagnostic settings in Azure? ›

Each Azure resource requires its own diagnostic setting, which defines the following criteria: Sources: The type of metric and log data to send to the destinations defined in the setting. The available types vary by resource type. Destinations: One or more destinations to send to.

How do I enable full diagnostic data? ›

Go to Start , then select Settings > Privacy & security > Diagnostics & feedback. Make sure that the View diagnostic data setting is turned On, and then select Open Diagnostic Data Viewer.

How do I enable diagnostic services? ›

Option 1: Via Services App
  1. Step 1: Press Windows + R to open Run window.
  2. Step 2: Input services. ...
  3. Step 3: Find Diagnostic Policy Service and double-click it to open its Properties.
  4. Step 4: Choose Automatic or Manual from the drop-down list of Startup type. ...
  5. Step 5: Click Apply and OK to save changes.
Jun 29, 2020

How do I enable Azure activity logs? ›

In the Azure portal, select Monitor > Workbooks. In the Insights section, select Activity Logs Insights. At the top of the Activity Logs Insights page, select: One or more subscriptions from the Subscriptions dropdown.

How do you detect and diagnose in Azure? ›

Triage and diagnose an alert

You can also open the Azure portal, navigate to the Application Insights resource for your app, and open the Failures page. Clicking on 'Diagnose failures' will help you get more details and resolve the issue.

How do I check access logs in Azure portal? ›

Access the activity logs in the portal
  1. Navigate to the Azure portal using one of the required roles.
  2. Go to Azure AD and select Audit logs, Sign-in logs, or Provisioning logs.
  3. Adjust the filter according to your needs.
Dec 19, 2022

How do I check Azure service connection? ›

Sign in to your organization ( https://dev.azure.com/{yourorganization} ) and select your project.
  1. Select Project settings > Service connections.
  2. Select the service connection that you want to edit.
  3. See the Overview tab of the service connection where you can see the details of the service connection.
Nov 28, 2022

How do you troubleshoot an application problem? ›

Eleven Tips for Troubleshooting Software
  1. Free up RAM by closing other open programs. ...
  2. Restart the software. ...
  3. Shut down and restart your computer. ...
  4. Use the Internet to find help. ...
  5. Undo any recent hardware or software changes. ...
  6. Uninstall the software, then reinstall it. ...
  7. Look for software patches. ...
  8. Scan for viruses and malware.

How do I debug an app on Azure App Service? ›

In Server Explorer, expand the Azure > App Service node. Locate the resource group that you created or selected when you deployed your API app. Under the resource group, right-click the node for your API app and select Attach Debugger. The remote debugger will try to connect.

What are Azure diagnostic logs? ›

Resource logs were previously referred to as diagnostic logs. Provides insight into the operations on each Azure resource in the subscription from the outside (the management plane) in addition to updates on Service Health events.

What are diagnostics logs used for? ›

Diagnostics logs allow you to export basic usage metrics from your CDN endpoint to different kinds sources so that you can consume them in a customized way. You can do the following types of data export: Export data to blob storage, export to CSV, and generate graphs in Excel.

What are the three types of logs? ›

Availability Logs: track system performance, uptime, and availability. Resource Logs: provide information about connectivity issues and capacity limits. Threat Logs: contain information about system, file, or application traffic that matches a predefined security profile within a firewall.

Where are diagnostic logs stored in Azure? ›

The diagnostics logs are saved in a blob container named $logs in your storage account. You can view the log data using a storage explorer like the Microsoft Azure Storage Explorer, or programmatically using the storage client library or PowerShell.

What is the difference between Azure diagnostics and resource specific? ›

Azure diagnostics: All data is written to the AzureDiagnostics table. Resource-specific: Data is written to individual tables for each category of the resource.

How do I enable ADF logging? ›

First, to enable this function, go to your copy activity. In the Settings section, click “Enable logging.”

How do I check logs of app services? ›

On the portal, click on “Log Stream” immediately below “App Services log” and you'll see the log messages in real time.

Videos

1. Diagnosing application crashes with Azure App Services
(Microsoft Azure)
2. Azure Spring Apps: The Easy Way to Run Your Apps
(SpringDeveloper)
3. Troubleshooting apps in Azure App Services
(Tahir Rauf)
4. Azure Application Insights Tutorial | Amazing telemetry service
(Adam Marczak - Azure for Everyone)
5. az-104 exam dumps 2023 |Microsoft Azure Administrator |AZ-104 Exam Dumps Questions & Answers
(Clearcat .net)
6. AZ 204 Enabling diagnostic logging
(Learn Smart Coding)
Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated: 10/24/2022

Views: 5968

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.