Azure provides in-buit support for diagnostics logging for Azure App Service. In this article, we will see how diagnostic logging can be enabled and how can we check the logs.
We will use Azure Portal in this article, but you can also use Azure CLI. For following some of the steps in this article, you will need an Azure account. If you do not have an Azure account, you can create free account on Azure.
Why Diagnostics Logging ?
Suppose you are working on a web application which is deployed as Azure App Service. You are developing a feature which is going to be live soon. You also want a simple and easy way to debug / troubleshoot the issues in the new feature, without adding any dependency on the new specialized logging packages e.g. Application Insight SDK.
If you are in this situation, then Diagnostics Logging is the way out.
What are Application Logs ?
Application logs are the output of runtime trace statements in the code. e.g. start of some function, end of some function, some errors in the function, data returned by a function, etc.
You may want to trace the information depending on level of the error / event. You can add trace statements which takes a message and level of event. Then you can set the trace level in the configurations, thereby optimizing the amount of logs generated by the application.
You can write logs either in a file (both Windows and Linux) or in a BLOB (only if you choose windows).
Below are some examples of how the trace statements look in different frameworks:
ASP .NET Windows Web Apps
The ASP .NET Apps run only on windows. You can use System.Diagnostics.Trace class for adding the logging.
The .NET Framework has log levels – error, warning, information and verbose, and they map to the Azure app service diagnostics log levels.
- Trace.TraceError(“trace”); // Writes an error message
- Trace.TraceWarning(“trace”); // Writes a warning message
- Trace.TraceInformation(“trace”); // Writes an information message
- Trace.WriteLine(“trace-message”); // Writes a verbose message
.NET Core Apps
The .NET Core Apps run on both Windows and Linux platforms. You need to use LoggerFactory class.
- LogCritical and LogError methods writes “error” messages
- LogWarning method write “warning” messages
- LogInformation method writes “information” messages
- LogDebug and LogTrace writes “verbose” messages
The Node.JS apps can use either console.error() or console.log() methods. Both of these methods write traces to error-level logs in Azure.
Enable Diagnostics Logging
Let’s have a look at how to enable diagnostics logging in your Azure App Service. We will use same app service which we created in one of my previous blog article.
Login to Azure Portal and Navigate to your App Service and select “App service logs“
You can see 4 types of settings:
Application Logging (File System or Blob)
Log messages are generated by your code (e.g. Trace.WriteLine). Each message can be assigned with one of the level – critical, error, warning, info, debug and trace. You can set how verbose your logs should be by setting the level while enabling the Application Logging.
If you select Blob, you have to provide the storage account container in which the logs would be written.
If you select File System, the logging would be turned off in 12 hours in order to optimize the storage space usage and performance of the application.
Web Server Logging (File System Or Blob)
Raw HTTP request data in the W3C extended log file format.
Detailed Error Messages
If the error code is greater than 400, the app service can store the HTML pages which otherwise would have been sent to the client. These pages can be useful to identify / troubleshoot the error.
Failed Request Tracking
Detailed information on failed requests including the web server components which were used to process the request and time that was taken to process the request.
In addition to these 4 settings, there is deployment logging which is always enabled.
Accessing the Log Files
For logs stored in the App Service file system, the easiest way is to download the ZIP file in the browser at:
For Linux/container apps, the zip file can be downloaded from
For Windows apps, the zip file can be downloaded from URL
In addition to this,
- /LogFiles/Application/ – for application logs
- /LogFiles/W3SVC#########/ – for failed requests logs
- /LogFiles/DetailedErrors/ – for detailed error logs
- /LogFiles/http/RawLogs/ – for web server logs
- /LogFiles/Git/ and /deployments/ – for deployment logs.
I hope this article has provided enough information to you for getting started with diagnostics logging. Please do comment and let me know your thoughts.