Exercise - Retrieve Application Log Files using Azure CLI and Kudu

Completed

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.

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 Cloud Shell file share, you'll use some Bash tools.

  1. 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>
    
  2. In Cloud Shell, to show the log files contained in the downloaded contosofashions.zip file, run the following command.

    zipinfo -1 contosofashions.zip
    
  3. 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
    
  4. In Cloud Shell, to display the application log file, run the following command.

    code *.txt
    
  5. 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.

  1. On the Azure portal menu, or from the Home page, select App Services. The App Services pane appears.

  2. In the App Services list, select contosofashions<your-number>. The contosofashions<your-number> App Service pane appears.

  3. In the middle menu pane, underDevelopment Tools, select Advanced Tools. The Advanced Tools pane appears.

  4. Select Go. The Kudu Services window appears.

  5. In the top menu bar, select Debug console, and then select CMD.

  6. In the file explorer section, select LogFiles.

  7. For the Application folder, select Download. The logs will be downloaded to your computer as Application.zip.

  8. On your computer, open Application.zip, and view the log file; this should be the same logs as you looked at using Cloud Shell.

  9. 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.

  1. On the Azure portal menu or from the Home page, select Storage accounts. The Storage accounts pane appears.

  2. In the Storage accounts list, select sacontosofashions<your-number>.

  3. In the middle menu pane, select Storage Explorer (preview). The Storage Explorer (preview) pane appears.

  4. In the Storage Explorer menu pane, expand BLOB CONTAINERS, and then select asplogs.

  5. In the container pane, double-click contosofashions<your-number>, then double-click each of the year, month, and date folders.

  6. 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).

  7. 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.

  8. In the opened log file, search for the following string.

    Warning message
    

    There should be several occurrences of this message in the log.

  9. Close the log file.