Exercise - View live application logging with the log streaming service using Azure CLI
As the lead web developer for Contoso Fashions, you want a quick view of your new web app's operation. 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 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 you enable in the app service. You enabled Error-level logging for the file system, so you only see LogError and LogCritical messages.
In this exercise, you open the log stream generated by your ASP.NET Web app by using Azure CLI commands from Cloud Shell.
In Cloud Shell, run the following command, replacing <NNNNN> with the unique identifier for your app, which you created in the previous exercise.
az webapp log tail --resource-group <rgn>[sandbox resource group name]</rgn> --name contosofashions<NNNNNN>
Wait until you see the Welcome, you are now connected to log-streaming service message.
Open or switch to the browser tab for Home Page - Contoso Fashions (contosofashionsNNNNN.azurewebsites.net), that you opened in the previous exercise.
In the menu bar, select About.
Return the Home page by selecting either Home or Contoso Fashions, and then select Contact.
From the Contact page, return to the website Home page by selecting Contoso Fashions.
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.
The log stream should display an entry for each page view, similar to the following output:
Error message, in the Page_Load method for Contact.aspx
In Cloud Shell, press Ctrl+C to stop the log stream session.