简体   繁体   English

自动将App Service诊断日志记录到存储

[英]Automate App Service diagnostic logging to Storage

I'm trying to automate the process of configuring Azure App Service to export diagnostic logs to Azure Storage, but I'm running into something I don't quite understand. 我正在尝试自动化配置Azure应用服务以将诊断日志导出到Azure存储的过程,但是遇到了我不太了解的问题。 I can take the following steps to get it working. 我可以按照以下步骤操作。

  1. I configure diagnostic logging in the Azure Portal, according to the documentation . 根据文档 ,我在Azure门户中配置诊断日志记录。 Everything looks good. 一切看起来都很好。 I can see the logs being populated in the storage containers. 我可以看到在存储容器中填充了日志。
  2. Using Azure Resource Explorer , I navigate to the config/logs resource and observe the JSON: 使用Azure Resource Explorer ,我导航到config/logs资源并观察JSON:

     "applicationLogs": { ... "azureBlobStorage": { "level": "Information", "sasUrl": "https://<storagename>.blob.core.windows.net/<container>?sv=YYYY-MM-DD&sr=c&sig=<sig>&st=YYYY-MM-DDTHH:MM:SSZ&se=YYYY-MM-DDTHH:MM:SSZ&sp=rwdl", "retentionInDays": null } }, "httpLogs": { ... "azureBlobStorage": { "sasUrl": "https://<storagename>.blob.core.windows.net/<container>?sv=YYYY-MM-DD&sr=c&sig=<sig>&st=YYYY-MM-DDTHH:MM:SSZ&se=YYYY-MM-DDTHH:MM:SSZ&sp=rwdl", "retentionInDays": null, "enabled": true } }, 
  3. I can then hard-code the sasUrl values in an ARM template with a config/logs resource, and everything still works. 然后,我可以使用config/logs资源在sasUrl模板中对sasUrl值进行硬编码,并且一切仍然可以进行。 I can verify this by first deleting the storage containers and disabling diagnostic logs, then redeploying the ARM template. 我可以先删除存储容器并禁用诊断日志,然后重新部署ARM模板来验证这一点。

After getting that working, I attempt to use the ARM template function listAccountSas to generate a new SAS for the storage resource. 在完成该工作之后,我尝试使用ARM模板函数listAccountSas为存储资源生成一个新的SAS。 However, the resulting SAS has a slightly different format than the one I obtained from Azure Resource Explorer: sv=YYYY-MM-DD&ss=b&srt=s&sp=rwdl&st=YYYY-MM-DDTHH%3AMM%3ASS.0000000Z&se=YYYY-MM-DDTHH%3AMM%3ASS.0000000Z&spr=https&sig=<sig> . 但是,生成的SAS格式与我从Azure资源浏览器获得的格式略有不同: sv=YYYY-MM-DD&ss=b&srt=s&sp=rwdl&st=YYYY-MM-DDTHH%3AMM%3ASS.0000000Z&se=YYYY-MM-DDTHH%3AMM%3ASS.0000000Z&spr=https&sig=<sig>

So what's going on here. 所以这是怎么回事。 How is the portal generating the SAS? 门户如何生成SAS? Is the listAccountSas function generating a token that will work in its place? listAccountSas函数是否listAccountSas生成将在其位置工作的令牌? Is there even a way to automate this configuration? 甚至有一种方法可以自动执行此配置?

As far I known, the ARM template function listAccountSas only can list value, it can't create new vaule.And you can't create a sasToken within the template. 据我所知,ARM模板函数listAccountSas仅可以列出值,不能创建新值,也不能在模板内创建sasToken。 I suggest you use Powershell to create a sasToken, store it in Azure KeyVault, and refer that KeyVault secret in the template. 我建议您使用Powershell创建一个sasToken,将其存储在Azure KeyVault中,然后在模板中引用该KeyVault机密。 Regarding how to use cert in the template, please refer to the document . 关于如何在模板中使用证书,请参考文档

$name = "your account"
$password = "your password"
$RGname = "your resource group name"
$accountNmae  ="your Storage Account name"
$containerNmae ="your container name"
$keyvaultNmae ="your Key Vault name"
$certName = "your cert name"
$location = ""

# login Azure 
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($name, $secpasswd)
Add-AzureRmAccount -Credential $mycreds

#create Azure storage SAS URL
$account = Get-AzureRmStorageAccount -ResourceGroupName $RGname  -Name $accountNmae
$SASURL = New-AzureStorageContainerSASToken -Container $containerNmae -Context $account.Context -Permission rwdl -ExpiryTime (Get-Date).AddYears(1) -FullUri

#create key vault
New-AzureRmKeyVault -VaultName $keyVaultName -resourceGroupName $RGname -Location $location -EnabledForTemplateDeployment
Set-AzureRmKeyVaultAccessPolicy -VaultName $keyVaultName -UserPrincipalName $name -PermissionsToSecrets set,delete,get,list

#create cert
$secretvalue = ConvertTo-SecureString $SASURL -AsPlainText -Force
Set-AzureKeyVaultSecret -VaultName $keyvaultNmae -Name "test" -SecretValue $secretvalue

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure 应用服务诊断 blob 未记录基于 nlog 的日志 - Azure app service diagnostic blob not logging nlog based logs 需要 powershell 脚本来启用存储帐户和密钥保管库的诊断日志记录 - Need powershell script to enable diagnostic logging for Storage account and Key vault Azure 策略存储 blobServices/tableServices/queueServices 诊断日志记录 - Azure Policy Storage blobServices/tableServices/queueServices Diagnostic Logging 在 Azure 中,是否可以创建补救策略以启用存储帐户中的诊断设置登录? - In Azure can you create a remdiation policy to enable logging in diagnostic settings in a storage account? 应用服务使用 az cli 创建诊断设置 - app service create diagnostic settings using az cli Azure 应用服务日志和诊断设置之间的区别 - Difference between Azure App Service logs and Diagnostic settings 找不到Azure应用服务诊断日志应用程序日志记录Blob存储URL 404 - Azure App Service Diagnostics Logs Application Logging Blob Storage URL Not Found 404 Azure云服务(经典)-以任何方式将Diagnostic.Trace日志记录到BLOB存储中 - Azure Cloud Service (Classic) - Any way to log Diagnostic.Trace logs to BLOB storage Select 在使用诊断设置传输到存储帐户时限制 App Insights 日志数据的列 - Select limited columns from App Insights log data while transferring to storage account using Diagnostic settings Microsoft Azure应用服务存储 - Microsoft Azure App Service Storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM