azure - 将 Azure Web App 诊断日志设置添加到 ARM 模板

标签 azure azure-resource-manager azure-web-app-service azure-rm-template

我正在寻找在模板部署阶段启用诊断日志设置(文件级别,而不是 blob)的选项。
我找到了以下example但是在 Github 上,它不起作用,说“Microsoft.Web/sites/logs”不是有效选项”
以下是我的模板的一部分:

{
          "apiVersion": "2015-08-01",
          "name": "logs",
          "type": "config",
          "location": "[resourcegroup().location]",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
          ],
          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Verbose"
              }
            },
            "httpLogs": {
              "fileSystem": {
                "retentionInMb": 100,
                "retentionInDays": 90,
                "enabled": true
              }
            },
            "failedRequestsTracing": {
              "enabled": true
            },
            "detailedErrorMessages": {
              "enabled": true
            }
          }
        },

此外,我还找到了 following关于类似问题的讨论,但主题启动者表示这段代码在大多数情况下都能正常工作。

最佳答案

如果要在部署 Azure WebApp 期间启用诊断日志设置。您可以使用以下演示代码来执行此操作。它在我这边工作正常。

Deploy.json

{
      "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "siteName": {
          "type": "string"
        },
        "appServicePlanName": {
          "type": "string"
        },
        "siteLocation": {
          "type": "string"
        },
        "workerSize": {
          "type": "string",
          "allowedValues": [
            "0",
            "1",
            "2"
          ],
          "defaultValue": "1"
        }
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "[parameters('appServicePlanName')]",
          "type": "Microsoft.Web/serverfarms",
          "location": "[parameters('siteLocation')]",
          "sku": {
            "name": "S1",
            "tier": "Standard",
            "capacity": 1
          },
          "properties": {
            "name": "[parameters('appServicePlanName')]"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "[parameters('siteName')]",
          "type": "Microsoft.Web/sites",
          "location": "[parameters('siteLocation')]",
          "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
          ],
          "properties": {
            "serverFarmId": "[parameters('appServicePlanName')]"
          },
          "resources": [
            {
              "apiVersion": "2015-08-01",
              "name": "logs",
              "type": "config",
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
              ],
              "properties": {
                "applicationLogs": {
                  "fileSystem": {
                    "level": "Verbose"
                  }
                },
                "httpLogs": {
                  "fileSystem": {
                    "retentionInMb": 100,
                    "retentionInDays": 90,
                    "enabled": true
                  }
                },
                "failedRequestsTracing": {
                  "enabled": true
                },
                "detailedErrorMessages": {
                  "enabled": true
                }
              }
            }
          ]
        }
      ]
    }

parameters.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "siteName": {
      "value": "xxxxxx"
    },
    "appServicePlanName": {
      "value": "xxxx"
    },
    "siteLocation": {
      "value": "East US"
    },
    "workerSize": {
      "value": "1"
    }
  }
}

从 Azure 门户检查。

enter image description here

关于azure - 将 Azure Web App 诊断日志设置添加到 ARM 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49314112/

相关文章:

azure - 如何设置 VM 操作系统在使用 ARM 模板创建时自动更新 - Azure

Azure VMSS 自定义脚本扩展错误 - 无法下载脚本文件

azure - 横向扩展 Azure 应用服务太慢

azure - 如何解决azure web应用程序部署未经授权(代码: 401)

javascript - 我需要为 "Application Insights for web pages"遥测调用创建代理终结点(Azure 函数代理失败 CORS 选项调用)

Azure Storm 与 A​​zure 流分析

node.js - Azure Functions 与 node.js、Azure 服务总线和 Apps Insight - AppsInsights 设置时出错

Azure 资源组不可用于已部署的资源

azure - 在哪里可以找到每种资源类型对 Azure 资源提供程序的作用

node.js - 如何让 Node.js 应用程序在 Azure 应用服务上运行?