(我将对这个问题做一些死灵法,因为这是我在寻找解决方案时发现的最相关的 StackOverflow 问题,因为不再可能通过经典门户做到这一点)
免责声明:Microsoft 似乎已经取消了对 Azure 门户中记录到 Table 的支持,所以我不知道这是否已被弃用或即将被弃用,但我有一个现在可以使用的解决方案 (31.03.2017):
有一些特定的设置决定了日志记录,我首先从 Azure Powershell github 中的一个问题中找到了这方面的信息:https://github.com/Azure/azure-powershell/issues/317
我们需要的具体设置是(来自github):
AzureTableTraceEnabled = True,& AppSettings 具有:
DIAGNOSTICS_AZURETABLESASURL
使用(GUI导航)下的优秀资源浏览器(https://resources.azure.com):
/subscriptions/{subscriptionName}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/config/logs
我能够在属性中找到设置 AzureTableTraceEnabled。
属性 AzureTableTraceEnabled 具有 Level 和 sasURL。根据我的经验,更新这两个值 (Level="Verbose",sasUrl="someSASurl") 将起作用,因为在 appsettings 中更新 sasURL 集 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 的方法,可以获取 Azure 存储帐户密钥(来自:ARM - How can I get the access key from a storage account to use in AppSettings later in the template?) :
"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 模板更新时(或者比我来开导我们)。