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

Completed

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
    gitRepo=https://github.com/MicrosoftDocs/mslearn-capture-application-logs-app-service
    appName="contosofashions$RANDOM"
    appPlan="contosofashionsAppPlan"
    resourceGroup=<rgn>[sandbox resource group name]</rgn>
    storageAccount=sa$appName
    appLocation=<your-local-Azure-region>
    
  2. Run the following commands to deploy the web app.

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

    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 Home page, in the Navigate section, select Subscriptions. The Subscriptions pane for your Microsoft Learn Sandbox appears.

  3. In the Subscription name list, select Concierge Subscription. The Concierge Subscription pane appears.

  4. Select Resources. The list of resources, in the Resource group column should show your sandbox resource group ([sandbox resource group name]).

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

  6. Select contosofashionsNNNNN, where NNNNN represents the random number generated for your app. The Overview pane for your App Service appears.

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

  8. In the Azure portal, in the App Services menu, scroll down to the Monitoring section and select App Service logs. The App Service logs pane appears.

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

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

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

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

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

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

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

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

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