(我将对这个问题做一些死灵术,因为这是我在寻找解决方案时发现的最相关的 StackOverflow 问题,因为不再可能通过经典门户来做到这一点)
免责声明:微软似乎已经删除了对登录到 Azure 门户中的表的支持,所以我不知道这是否已被弃用或即将被弃用,但我有一个现在可以使用的解决方案(2017 年 3 月 31 日):
有一些特定的设置决定日志记录,我首先从 Azure Powershell github 中的一个问题中找到了这方面的信息:https://github.com/Azure/azure-powershell/issues/317
我们需要的具体设置是(来自github):
AzureTableTrace Enabled = True,在 AppSettings 中有:诊断 AZURETABLESASURL
使用优秀的资源浏览器(https://resources.azure.com)在(GUI 导航)下:
/subscriptions/{subscriptionName}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/config/logs
我能够在属性中找到设置 AzureTableTraceEnabled。
属性 AzureTableTraceEnabled 具有 Level 和 sasURL。根据我的经验,更新这两个值(Level =“Verbose”,sasUrl =“someSASurl”)将起作用,因为更新 sasURL 在 appsettings 中设置 DIAGNOSTICS_AZURETABLESASURL 。
我们如何改变这一点?我是在 Powershell 中完成的。我第一次尝试了 cmdlet Get-AzureRmWebApp,但找不到我想要的东西 - 旧的 Get-AzureWebSite 确实显示 AzureTableTraceEnabled,但我无法更新它(也许具有更多 powershell\azure 经验的人可以输入有关如何使用 ASM cmdlet 来执行此操作)。
对我有用的解决方案是通过 Set-AzureRmResource 命令设置属性,并进行以下设置:
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName "$ResourceGroupName" -ResourceType Microsoft.Web/sites/config -ResourceName "$ResourceName/logs" -ApiVersion 2015-08-01 -Force
其中 $PropertiesObject 如下所示:
$PropertiesObject = @{applicationLogs=@{azureTableStorage=@{level="$Level";sasUrl="$SASUrl"}}}
级别对应于“错误”、“警告”、“信息”、“详细”和“关闭”。
也可以在 ARM 模板中执行此操作(重要位位于站点中日志资源的属性中):
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "WebApp"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
],
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
},
"resources": [
{
"name": "logs",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites/', variables('webSiteName'))]"
],
"tags": {
"displayName": "LogSettings"
},
"properties": {
"azureTableStorage": {
"level": "Verbose",
"sasUrl": "SASURL"
}
}
}
}
在 ARM 中执行此操作的问题是我还没有找到生成正确 SAS 的方法,它is可以提取 Azure 存储帐户密钥(来自:ARM - 如何从存储帐户获取访问密钥以在模板后面的 AppSettings 中使用?):
"properties": {
"type": "AzureStorage",
"typeProperties": {
"connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]"
}
}
还有一些使用链接模板生成它们的巧妙方法(来自:http://wp.sjkp.dk/service-bus-arm-templates/).
我当前寻求的解决方案(时间限制)是一个自定义的 Powershell 脚本,如下所示:
...
$SASUrl = New-AzureStorageTableSASToken -Name $LogTable -Permission $Permissions -Context $StorageContext -StartTime $StartTime -ExpiryTime $ExpiryTime -FullUri
$PropertiesObject = @{applicationLogs=@{azureTableStorage=@{level="$Level";sasUrl="$SASUrl"}}}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName "$ResourceGroupName" -ResourceType Microsoft.Web/sites/config -ResourceName "$ResourceName/logs" -ApiVersion 2015-08-01 -Force
...
这是一个相当丑陋的解决方案,因为除了 ARM 模板之外,您还需要维护一些额外的东西 - 但它很简单、快速,并且在我们等待 ARM 模板更新时(或者比我更聪明的人来)它可以工作并启发我们)。