Exercise - Enable and configure App Service application logging using the Azure portal

Completed 100 XP

This module requires a sandbox to complete. A sandbox gives you access to free resources. Your personal subscription will not be charged. The sandbox may only be used to complete training on Microsoft Learn. Use for any other reason is prohibited, and may result in permanent loss of access to the sandbox.

Microsoft provides this lab experience and related content for educational purposes. All presented information is owned by Microsoft and intended solely for learning about the covered products and services in this Microsoft Learn module.

In this exercise, you deploy a sample ASP.NET Core Web app from GitHub, which has the code required to generate trace output messages. Then, you use the Azure portal to enable app logging for the app.

Use Azure CLI to deploy a web app

In this task, you use Azure CLI to create an ASP.NET Web app using code from a GitHub repository. You also create a new storage account in the same region as the Web app, for log storage.

  1. Let's set some variables, so we can use them throughout the rest of the exercise. Run the following commands in Azure Cloud Shell, replacing <your-local-Azure-region>, with the region closest to you from the following list.

    The free sandbox allows you to create resources in a subset of the Azure global regions. Select a region from this list when you create resources:

    • westus2
    • southcentralus
    • centralus
    • eastus
    • westeurope
    • southeastasia
    • japaneast
    • brazilsouth
    • australiasoutheast
    • centralindia
    Bash
    gitRepo=https://github.com/MicrosoftDocs/mslearn-capture-application-logs-app-service
    appName="contosofashions$RANDOM"
    appPlan="contosofashionsAppPlan"
    resourceGroup=[sandbox resource group name]
    storageAccount=sa$appName
    appLocation=<your-local-Azure-region>
    
  2. Run the following commands to deploy the web app.

    Azure CLI
    az appservice plan create --name $appPlan --resource-group $resourceGroup --location $appLocation --sku FREE
    az webapp create --name $appName --resource-group $resourceGroup --plan $appPlan --deployment-source-url $gitRepo
    

    The app can take several minutes to deploy.

  3. Make a note of your app name, including the random number that was generated to uniquely identify your app. It should resemble something like: contosofashions13642.azurewebsites.net.

  4. Run the following command to create a storage account.

    Azure CLI
    az storage account create -n $storageAccount -g $resourceGroup -l $appLocation --sku Standard_LRS 
    

Wait for the command to complete, and then continue with this exercise.

Enable logging using the Azure portal

In this task, you use the Azure portal to enable app logging for the file system and Azure Blob storage. Start by verifying that your Web app is running.

  1. Sign in to the Azure portal using the same account used to activate the sandbox.

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

  3. In the App Services list, select contosofashions<your-number>. The contosofashions<your-number> Web App menu appears.

  4. On the Web App menu, in the Essentials section, copy the default domain and paste it in a new browser tab (For example, contosofashionsNNNNN.azurewebsites.net). The home page for Contoso Fashions should appear.

    Let's set up app logging.

  5. On the left-hand menu for your Web App, scroll down to the Monitoring section and expand it if necessary. Select App Service logs. The App Service logs pane appears.

  6. Under Application Logging (Filesystem), select On, and in the Level box dropdown list, select Error.

  7. Under Application Logging (Blob), select On, and in the Level box dropdown list, select Verbose.

  8. Select the 0 link under Storage Containers. The Storage accounts pane appears.

    Note

    If a notification Storage not configured appears, select that text, and complete the previous 3 steps.

  9. In the Name list, select sacontosofashionsNNNN, where NNNN is the number you noted when you created your app. The Containers pane appears.

  10. In the command bar, select Container. The New container pane appears.

  11. In the Name box, enter appsrvplogs, and then select Create.

  12. In the Containers pane, select appsrvplogs, and then choose Select. The App Service logs pane appears.

  13. In the Retention Period (Days) box, enter 5.

  14. In the command bar, select Save to update the log settings and close the logs pane.


Next unit: View live application logging with the log streaming service

Previous Next