Azure CLI-配置应用程序服务日志
我正在尝试使用Azure CLI为Azure Web应用程序配置应用程序日志记录(Blob)和Web服务器日志记录(存储)设置 我正在使用以下命令创建存储容器: az存储容器创建--帐户名StorageAccName--名称ContainerName--身份验证模式登录 但是,我无法链接Web应用中的存储设置以使用新容器 我在参考文档中找不到任何东西 有人有聪明的方法来配置此设置吗?谢谢 根据krishg的答案更新了最终解决方案。Azure CLI-配置应用程序服务日志,azure,azure-web-app-service,azure-cli,Azure,Azure Web App Service,Azure Cli,我正在尝试使用Azure CLI为Azure Web应用程序配置应用程序日志记录(Blob)和Web服务器日志记录(存储)设置 我正在使用以下命令创建存储容器: az存储容器创建--帐户名StorageAccName--名称ContainerName--身份验证模式登录 但是,我无法链接Web应用中的存储设置以使用新容器 我在参考文档中找不到任何东西 有人有聪明的方法来配置此设置吗?谢谢 根据krishg的答案更新了最终解决方案。 $webAppName = "containerN
$webAppName = "containerName"
$accountName = "accountName"
$accountKey = "accountKey"
$containerExists = az storage container exists --name $webAppName --account-name $accountName --auth-mode login | ConvertFrom-Json
"Container Exists: " + $containerExists.exists
if (!$containerExists.exists)
{
$container = az storage container create --account-name $accountName --name $webAppName --auth-mode login | ConvertFrom-Json
"Container Created: " + $container.created
}
$sas = az storage container generate-sas --account-name $accountName --expiry "2220-01-01" --name $webAppName --permissions dlrw --account-key $accountKey --start "2020-11-25T12:15:09Z"
$sasUrl = '"https://' + $accountName + '.blob.core.windows.net/' + $webAppName + '?' + $sas.Trim('"') + '"'
"Storage Account Container Shared Access Signature (SAS) URL: "
$sasUrl
$appServiceLogSettings = az webapp log show --name $webAppName --resource-group $resourceGroup | ConvertFrom-Json
$webapplog = az resource update --ids $appServiceLogSettings.id --set properties.applicationLogs.azureBlobStorage.sasUrl=$sasUrl, properties.applicationLogs.azureBlobStorage.retentionInDays="365", properties.applicationLogs.azureBlobStorage.level="Error", properties.httpLogs.azureBlobStorage.sasUrl=$sasUrl, properties.httpLogs.azureBlobStorage.retentionInDays="365", properties.httpLogs.azureBlobStorage.enabled="true", properties.detailedErrorMessages.enabled="true", properties.failedRequestsTracing.enabled="true" | ConvertFrom-Json
"Application Logging (Blob) Level: " + $webapplog.properties.applicationLogs.azureBlobStorage.level
"Application Logging (Blob) RetentionInDays: " + $webapplog.properties.applicationLogs.azureBlobStorage.retentionInDays
"Application Logging (Blob) SAS URL: " + $webapplog.properties.applicationLogs.azureBlobStorage.sasUrl
"Web Server Logging (Blob) Enabled: " + $webapplog.properties.httpLogs.azureBlobStorage.enabled
"Web Server Logging (Blob) RetentionInDays: " + $webapplog.properties.httpLogs.azureBlobStorage.retentionInDays
"Web Server Logging (Blob) SAS URL: " + $webapplog.properties.httpLogs.azureBlobStorage.sasUrl
"Detailed Error Messages: " + $webapplog.properties.detailedErrorMessages.enabled
"Failed Requests Tracing: " + $webapplog.properties.failedRequestsTracing.enabled
我同意,没有在
az webapp log config
中设置存储帐户的选项有点令人沮丧。但您可以执行以下操作来在日志配置中设置存储设置
- 使用生成具有所需到期日的存储容器的sas令牌。下面就是我的例子
- 获取应用程序服务的日志配置的资源id
- 使用上面生成的sas令牌设置日志配置的属性
az resource update --ids $logConfigResourceId --set properties.applicationLogs.azureBlobStorage.sasUrl=$sasUrl,properties.httpLogs.azureBlobStorage.sasUrl=$sasUrl,properties.httpLogs.azureBlobStorage.enabled=true
如果要更新任何其他设置,要了解日志配置资源的结构,可以运行az webapp log show--name MyWebApp--resource group MyResourceGroup
$logConfigResourceId = az webapp log show --name MyWebApp --resource-group MyResourceGroup --query 'id' -o json
az resource update --ids $logConfigResourceId --set properties.applicationLogs.azureBlobStorage.sasUrl=$sasUrl
az resource update --ids $logConfigResourceId --set properties.httpLogs.azureBlobStorage.sasUrl=$sasUrl
az resource update --ids $logConfigResourceId --set properties.httpLogs.azureBlobStorage.enabled=true
az resource update --ids $logConfigResourceId --set properties.applicationLogs.azureBlobStorage.sasUrl=$sasUrl,properties.httpLogs.azureBlobStorage.sasUrl=$sasUrl,properties.httpLogs.azureBlobStorage.enabled=true