在ARM模板中添加Azure Web App文件级诊断日志设置
解决Azure Web App诊断日志模板部署报错问题
你碰到的这个报错,核心原因是API版本不匹配导致的资源类型定义问题。在2015-08-01这个旧API版本里,Web App的日志配置并不是作为独立的config类型资源(Microsoft.Web/sites/logs)来定义的,而是直接嵌套在Web App主资源的properties.siteConfig下面。
正确的模板写法
这里给你两种可行的解决方案,根据你的需求选择:
方案1:升级API版本并使用独立日志资源
如果想保留独立的日志配置块,把API版本升级到2021-03-01(或更新的稳定版本),此时Microsoft.Web/sites/logs是有效的资源类型:
{ "apiVersion": "2021-03-01", "name": "[concat(parameters('siteName'), '/logs')]", "type": "Microsoft.Web/sites/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 } } }
注意这里的name要写成[concat(parameters('siteName'), '/logs')],明确关联到对应的Web App资源。
方案2:在Web App主资源中嵌套日志配置
如果你想继续使用2015-08-01版本,需要把日志配置放到Web App的siteConfig里,示例如下:
{ "apiVersion": "2015-08-01", "name": "[parameters('siteName')]", "type": "Microsoft.Web/Sites", "location": "[resourceGroup().location]", "properties": { // 这里填写Web App的其他基础配置,比如serverFarmId等 "siteConfig": { "httpLoggingEnabled": true, "detailedErrorLoggingEnabled": true, "failedRequestTracingEnabled": true, "logging": { "applicationLogs": { "fileSystem": { "level": "Verbose" } }, "httpLogs": { "fileSystem": { "retentionInMb": 100, "retentionInDays": 90, "enabled": true } } } } } }
为什么有些场景下原代码能运行?
你提到的论坛里说这段代码多数情况正常,大概率是因为那些场景使用了更高版本的API,或者是在旧的Azure资源管理器兼容模式下运行的(现在已经逐步被淘汰)。新的ARM模板规范中,不同API版本对应的资源结构有明确差异,必须严格匹配版本要求才能正常部署。
内容的提问来源于stack exchange,提问作者Sergey
相关产品推荐
相关产品推荐

