Diagnosing troubles in an app can be challenging which is why feedback is so critical. Learn how to enable diagnostic logs for an app in Azure, including the location of logging files, and how to download them.
- [Instructor] The Azure app service has built-in diagnostics that can help you debug your apps. The service is not enabled by default, that you must do yourself. But once enabled, you are able to download the logs. And again, depending on your preference, you have a couple of options. First of all, you can download them via FTP. And the actual links for the FTB downloads are in the Diagnostics Logs blade, and I'll show that to you in a moment, when we pop into the demo. You can download the logs via PowerShell, using the Save-AzureWebSiteLog, and then providing the name of the app.
For those of you who like command line interface, the command will be Azure site log download, again providing the name of the app. And finally, in Visual Studio, you can view the logs using the applications inside SDK. Before you download the logs, you'll need to understand the log structure. The application logs are located in the LogFiles/Application folder. Failed request logs are in the LogFiles/W3SVC, and then the corresponding folder name.
The detailed error logs are in the LogFiles/DetailedErrors. And the web server logs are in LogFiles/http/RawLogs files. And finally, your deployment logs are in the LogFiles/Git folder. And these files are in Azure storage. Let's go ahead and take a look at how we enable our logs in Azure. We are currently looking at the MyWebAppSB web app. And in order to enable your diagnostics, you'll need to scroll down, all the way down, under Monitoring, and then Diagnostic Logs.
And here you'll see that everything is Off by default. You need to go ahead and enable the diagnostics that you wish to capture. Our first option is Application Logging Filesystem. Enabling this allows diagnostic traces from your web app code. This must be enabled if you'd like to view streaming logs. And keep in mind, this setting will only be enabled for 24 hours. I'm going to go ahead and turn that on, because we will want to view the streaming logs.
And next, you can choose your level of warning. You can have this log the errors, warnings, information or verbose. We're going to go ahead and do verbose. Next we have our application logging. When we enable application logging, the logs are stored in Blob containers in storage. Remember the file structure we just discussed? I'm going to go ahead and turn this on.
Again, we're going to select our level. But here you have to configure the storage settings. These are not configured for you automatically. In order to do so, click Storage account. We're just going to add in a storage account. You can select the performance of Standard or Premium. And then we're going to pick whether or not it's Locally redundant storage, zone, geo or read-access geo-redundant storage.
Because these are log files, I'm just going to do them in Locally-redundant storage. Again, depending on your tier, this will dictate your costs. For more information, see the Azure course on storage. You'll notice I'm unable to save this as of yet, and this is because I've used upper case within my name. I now am able to go ahead and click OK.
This will take a moment. And we can now see that our storage account has been created. I can go ahead and close this blade. Next, we have our web server logging. And here we can collect info about our web server that is hosting our app. And again, you can choose it for storage or for file system. Under file system, we have a quota. And this will allow for the maximum size of our log files.
And then next we have a retention period. By default your log files will be kept forever. You may not want this, because it will chew up a lot of storage, so you can go ahead and set a retention period in here. I'm going to go ahead and have a retention period of 15 days. And then finally, we're down to our last two options. We have our detailed error messages, which will collect, as it states, detailed errors from our web app, and our failed request tracing, which will gather information on our failed requests.
And we can turn these off or on as required. I'm going to enable them for our download purposes. Remember I mentioned you can download your files via FTP? Here are the links in order to do so. You could just go ahead and copy that information into your favorite FTP client. I'm going to go ahead and click Save. And that's it. We have now enabled diagnostics, and we are retaining those logs.
- Deploying Web Apps
- Creating App Service plans
- Deploying and moving apps
- Configuring app settings
- Managing Web Apps using PowerShell and CLI
- Configuring alerts
- Enabling diagnostic logs
- Retrieving and streaming logs
- Configuring Web Apps for scale and resilience