Exercise - Retrieve Application Log Files using Azure CLI and Kudu
Your new Web App for Contoso Fashions is nearly ready for some initial pilot testing. You want to review and analyze all the various trace messages that were saved to your app's log files. Before you can do any review, you need to know how to find the logged information.
In this unit, you retrieve log files ready for later offline analysis.
Retrieve file system logs using Azure CLI
In this step, you use Azure CLI to retrieve file system logs to your cloud share storage, and then view these logs.
Note
The full Cloud Shell has a toolbar that includes a file download and upload tool, and you could use this option to download contosofashions.zip to your local computer. This functionality is not currently available in the Microsoft Learn sandbox shell. So, in this exercise, to view the logs from within the Cloud Shell file share, we use some Bash tools.
In Cloud Shell, to download the logs to contosofashions.zip in the cloud share storage, replacing <your-number> with the random number that was generated to uniquely identify your app, run the following command.
az webapp log download --log-file contosofashions.zip --resource-group <rgn>[sandbox resource group name]</rgn> --name contosofashions<your-number>
In Cloud Shell, to show the log files contained in the downloaded contosofashions.zip file, run the following command.
zipinfo -1 contosofashions.zip
In Cloud Shell, to extract just the app log file from the downloaded contosofashions.zip file, run the following command.
unzip -j contosofashions.zip LogFiles/Application/*.txt
In Cloud Shell, to display the application log file, run the following command.
code *.txt
Note
If you see a prompt to Switch to Classic Cloud shell, select Confirm. Then, re-enter the previous command
code *.txt
to display the application log file.In Cloud Shell, press Ctrl+Q to close the editor.
Retrieve file system logs using Kudu
In this step, to download file system logs to your computer, use the Kudu console.
On the Azure portal menu, or from the Home page, select App Services. The App Services pane appears.
In the App Services list, select contosofashions<your-number>. The contosofashions<your-number> App Service pane appears.
In the middle menu pane, under Development Tools, select Advanced Tools. The Advanced Tools pane appears.
Select Go. The Kudu Services window appears.
In the top menu bar, select Debug console, and then select CMD.
In the file explorer section, select LogFiles.
For the Application folder, select Download. The logs are downloaded to your computer as Application.zip.
On your computer, open Application.zip, and view the log file. These logs should be the same as the ones you looked at using Cloud Shell.
Close the Kudu Services tab.
Search logs saved in Azure Blob Storage
In this procedure, you open the verbose logs that were saved into your Azure Blob Storage container, and then search for specific log entries.
On the Azure portal menu or from the Home page, select Storage accounts. The Storage accounts pane appears.
In the Storage accounts list, select sacontosofashions<your-number>.
In the middle menu pane, select Storage browser. The Storage browser pane appears.
Expand Blob containers, and then select appsrvplogs.
In the container pane, double-click contosofashions<your-number>, then double-click each of the year, month, and date folders.
You should now see a folder for each hour that the application has been logging to blob storage. Double-click the hour folder (or the earliest, if there's more than one).
The folder should contain one or more CSV files; to download it, double-click the largest file (you might need to scroll right to see the file sizes). If you have Microsoft Excel on your computer, the log file automatically opens as a worksheet. Otherwise, open the file using a text editor, such as Notepad.
In the opened log file, search for the following string.
Warning message
There should be several occurrences of this message in the log.
Close the log file.