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, and you'd like to review and analyze all the various trace messages that have been 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'll retrieve log files ready for later offline analysis.
Retrieve file system logs using Azure CLI
In this step, you'll use Azure CLI to retrieve file system logs to your cloud share storage, and then view these logs.
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 Cloud Shell file share, you'll 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.
Click in Cloud Shell, and to close the editor, press Ctrl+Q.
Retrieve file system logs using Kudu
In this step, to download file system logs to your computer, you'll 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, underDevelopment 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 will be downloaded to your computer as Application.zip.
On your computer, open Application.zip, and view the log file; this should be the same logs as you looked at using Cloud Shell.
Close the Kudu Services tab.
Search logs saved in Azure Blob Storage
In this procedure, you'll 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 Explorer (preview). The Storage Explorer (preview) pane appears.
In the Storage Explorer menu pane, expand BLOB CONTAINERS, and then select asplogs.
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 is more than one).
The folder should contain one or more CSV files; to download it, double-click the largest file (you may need to scroll right to see the file sizes). If you have Microsoft Excel on your computer, the log file will automatically open as a worksheet; otherwise, open the file using a text editor, such as Notepad.
In the opened log file, search for the following string.
There should be several occurrences of this message in the log.
Close the log file.