如何将 BlobStorage 用于 Azure Web 应用程序诊断日志(使用 SDK)

How to use BlobStorage for Azure Web App Diagnostics logs (using SDK)

我正在使用 Microsoft.Azure.Management.Websites SDK 部署 Azure Web 应用程序。

我可以使用 WebSiteManagementClient.Sites.CreateOrUpdateSite() 创建 Web 应用程序。但是,我似乎无法配置的一个元素是诊断日志记录。

在新的 Azure 门户中,我可以打开 "Diagnostics logs" 并定义 "Application Logging" 和 "Web server logging" 以使用 Blob 存储。

我在 SDK 库中看不到任何用于配置它的选项 - 谁有任何想法?如果需要,我愿意使用 ARM 模板。

提前致谢

已解决:方法 WebSiteManagementClient.Sites.UpdateSiteLogsConfig() 是定义诊断的地方

或者,您还可以配置诊断日志,以使用下面的 ARM 模板部分为 Web 应用程序启用 blob 存储日志记录。

{
  "type": "Microsoft.Web/sites",
  "name": "[parameters('webapp_name')]",
  "apiVersion": "2015-08-01",
  "location": "Southeast Asia",
  "properties": {
    "name": "[parameters('webapp_name')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('serverfarms_name'))]"
  },
  "resources": [
    {
      "name": "logs",
      "type": "config",
      "apiVersion": "2015-08-01",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('webapp_name'))]"
      ],
      "properties": {
        "applicationLogs": {
          "fileSystem": {
            "level": "Off"
          },
          "azureTableStorage": {
            "level": "Off",
            "sasUrl": null
          },
          "azureBlobStorage": {
            "level": "Verbose",
            "sasUrl": "yourBlobStorageSasUrl",
            "retentionInDays": null
          },
          "httpLogs": {
            "fileSystem": {
              "retentionInMb": 35,
              "retentionInDays": null,
              "enabled": false
            },
            "azureBlobStorage": {
              "sasUrl": "yourBlobStorageSasUrl",
              "retentionInDays": null,
              "enabled": true
            }
          }
        }
      }
    }
  ],
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', parameters('serverfarms_name'))]"
  ]
}