Coder Perfect

Set the App Service log retention period in Azure WebApp Deployment.

Problem

I’m using the az CLI and Biceps files to launch an Azure WebService (Linux Container). An excerpt from my logging settings is shown below.

resource appConfigLogs 'Microsoft.Web/sites/config@2021-02-01' = {
  name: 'logs'
  parent: app
  properties: {
    detailedErrorMessages: {
      enabled: true
    }
    failedRequestsTracing: {
      enabled: true
    }
    httpLogs: {
      fileSystem: {
        enabled: true
        retentionInDays: 7
        retentionInMb: 50
      }
    }
  }
}

According to my understanding, the setting “retentionInDays” correlates to “Retention Period (Days)” in the Azure Portal’s WebApp Resource > “Monitoring” > “App Servicing” section.

When setting via Portal, the App Services Configuration gets updated with an Application setting called “WEBSEITE_HTTPLOGGING_RETENTION_DAYS” set to the respective value.

There is no Configuration value set when setting via ARM Deplyment (see Biceps above). Is this a glitch, or do the two parameters “retentionInDays” and “Retention Period (Days)” simply don’t match?

Asked by Jensen

Solution #1

This isn’t a flaw. There are no separate parameters for “retentionInDays” and “Retention Period (Days).” In order to use retention period to keep logs for a period of time, we use the retentionInDays parameter in the ARM template setup. The same parameter will be presented in the portal as RententionPeriod (Days)

We created an ARM template and tried it in our local environment, which was successful. As shown below, this template will establish a web app, a storage account, enable app service logs, and set the application option WEBSEITE HTTPLOGGING RETENTION DAYS.

For additional information on setting app server logs to a storage account using an ARM template, see this blog post.

Answered by VenkateshDodda-MT

Post is based on https://stackoverflow.com/questions/70032043/set-retention-period-for-app-service-logs-in-azure-webapp-deployment