通过CLI创建诊断设置时指定AllLogs日志类别报错
解决Azure CLI创建诊断设置时AllLogs类别不支持的问题
问题原因
并非所有Azure资源都支持AllLogs作为日志类别,你操作的flexibleServers资源(如Azure Database for PostgreSQL Flexible Server)属于不支持该通用类别的资源类型,必须指定其实际支持的具体日志类别。
解决步骤
- 查询目标资源支持的日志类别
执行以下CLI命令获取该资源所有可用的日志类别:
az monitor diagnostic-settings categories list --resource /subscriptions/xxxxxx/resourceGroups/xxxx/providers/xxxxx/flexibleServers/xxx
命令返回结果会包含该资源支持的所有日志类别名称。
- 修改诊断设置命令
将原命令中的AllLogs替换为查询到的具体类别名称。例如,如果返回的类别包含PostgreSQLLogs,修改后的命令如下:
az monitor diagnostic-settings create --name KeyVault-Diagnostics --resource /subscriptions/xxxxxx/resourceGroups/xxxx/providers/xxxxx/flexibleServers/xxx --logs "[{\"category\": \"PostgreSQLLogs\",\"enabled\": true}]" --storage-account /subscriptions/xxxxx/resourceGroups/xxxxx/providers/xx/storageAccounts/xxxx
若需启用多个日志类别,可在--logs参数的数组中添加多个类别对象:
--logs "[{\"category\": \"PostgreSQLLogs\",\"enabled\": true}, {\"category\": \"ConnectionLogs\",\"enabled\": true}]"
内容的提问来源于stack exchange,提问作者Eze Opara
相关产品推荐
相关产品推荐

