Exercise - View live application logging with the log streaming service using Azure CLI

Completed

As the lead web developer for Contoso Fashions, you want a quick view of your new web app's operation. You know there will be issues, so rather than having to find and open log files, you want to use log streaming to view logged messages as you troubleshoot your app.

In this unit, you're going to use Azure CLI and Curl commands to view the live log stream generated by your Web app.

Use Azure CLI to view the live log stream

The ASP.NET app that you've deployed includes the following code for the home page.

logger.LogInformation("Information message from OnGet method on Index.cshtml page");
logger.LogDebug("Debug message from OnGet method on Index.cshtml page");
logger.LogError("Error message from OnGet method on Index.cshtml page");
logger.LogWarning("Warning message from OnGet method on Index.cshtml page");
logger.LogTrace("Trace message from OnGet method on Index.cshtml page");
logger.LogCritical("Critical message from OnGet method on Index.cshtml page");

Similar code is included on the other pages. Each time a page is loaded, a log entry is generated for every log level that has been enabled in the app service. You enabled Error-level logging for the file system, so you will only see LogError and LogCritical messages.

In this exercise, you'll open the log stream generated by your ASP.NET Web app by using Azure CLI commands from Cloud Shell.

  1. In Cloud Shell, run the following command, replacing <NNNNN> with the unique identifier for your app.

    az webapp log tail  --resource-group <rgn>[sandbox resource group name]</rgn> --name contosofashions<NNNNNN>
    
  2. Wait until you see the Welcome, you are now connected to log-streaming service message.

  3. Switch to the browser tab for Home Page - Contoso Fashions (https://contosofashions<NNNNN>.azurewebsites.net).

  4. In the menu bar, select About.

  5. Return the Home page by selecting either Home or Contoso Fashions, and then select Contact.

  6. From the Contact page, return to the website Home page by selecting Contoso Fashions.

  7. In Cloud Shell, you should see log entries generated by each page in the ASP.NET app.

    Note

    If you do not see any log data, run the CLI command again and wait a few minutes for the Welcome notification to appear.

  8. The log stream should display an entry for each page view, similar to the following:

    Error message, in the Page_Load method for Contact.aspx
    
  9. Click in Cloud Shell, and press Ctrl+C to stop the log stream session.