为什么不能将Azure诊断配置为通过新的Azure门户使用Azure表存储? [英] Why can't configure Azure diagnostics to use Azure Table Storage via new Azure Portal?
问题描述
我正在开发将在Azure中托管的Web API.我想使用Azure诊断程序将错误记录到Azure表存储中. 在经典门户中,我可以配置日志以转到Azure表存储.
I am developing a web api which will be hosted in Azure. I would like to use Azure diagnostics to log errors to Azure table storage. In the Classic portal, I can configure the logs to go to Azure table storage.
但是在新的Azure门户中,我唯一的存储选项是使用Blob存储:
However in the new Azure portal, the only storage option I have is to use Blob storage:
似乎,如果我要使用Web角色,则可以配置数据存储以进行诊断,但是在开发Web api时,我不想为每个api创建一个单独的web角色我可以登录到天蓝色表.
It seems that if I was to make use of a web role, I could configure the data store for diagnostics but as I am developing a web api, I don't want to create a separate web role for every api just so that I can log to an azure table.
是否可以通过编程方式配置天蓝色诊断程序,以在不使用Web角色的情况下将日志消息传播到特定的数据存储区?为什么新的Azure门户仅对blob存储具有诊断设置,而对表存储却没有诊断设置?
Is there a way to programmatically configure azure diagnostics to propagate log messages to a specific data store without using a web role? Is there any reason why the new Azure portal only has diagnostic settings for blob storage and not table storage?
我目前可以使用经典门户解决该问题,但我担心诊断表存储将最终被弃用,因为新门户的诊断设置中未包含该表存储.
I can currently work around the problem by using the classic portal but I am worried that table storage for diagnostics will eventually become deprecated since it hasn't been included in the diagnostic settings for the new portal.
推荐答案
(我将对此问题进行一些整理,因为这是我在寻找解决方案时发现的最相关的StackOverflow问题,因为它不再可能通过经典门户网站来做到这一点)
(I'll do some necromancy on this question as this was the most relevant StackOverflow question I found while searching for a solution to this as it is no longer possible to do this through the classic portal)
免责声明:Microsoft似乎已经删除了对Azure门户中记录到表的支持,因此我不知道此记录是否已被弃用或即将被弃用,但是我有一个可以立即使用的解决方案(2017年3月31日):
Disclaimer: Microsoft has seemingly removed support for logging to Table in the Azure Portal, so I don't know if this is deprecated or will soon be deprecated, but I have a solution that will work now (31.03.2017):
有确定日志记录的特定设置,我首先从Azure Powershell github中的问题中找到了有关此信息: https://github.com/Azure/azure-powershell/issues/317
There are specific settings determining logging, I first found out information on this from an issue in the Azure Powershell github: https://github.com/Azure/azure-powershell/issues/317
我们需要的特定设置是(来自github):
The specific settings we need are (from github):
AzureTableTraceEnabled = True,& AppSettings具有: DIAGNOSTICS_AZURETABLESASURL
AzureTableTraceEnabled = True, & AppSettings has: DIAGNOSTICS_AZURETABLESASURL
在(GUI导航)下使用出色的资源浏览器( https://resources.azure.com ). :
Using the excellent resource explorer (https://resources.azure.com) under (GUI navigation):
/subscriptions/{subscriptionName}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/config/logs
/subscriptions/{subscriptionName}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/config/logs
我能够在属性中找到设置AzureTableTraceEnabled.
I was able to find the Setting AzureTableTraceEnabled in the Properties.
属性AzureTableTraceEnabled具有级别和sasURL.以我的经验,更新这两个值(Level ="Verbose",sasUrl ="someSASurl")会起作用,因为更新appssettings中的sasURL设置了DIAGNOSTICS_AZURETABLESASURL.
The property AzureTableTraceEnabled has Level and sasURL. In my experience updating these two values (Level="Verbose",sasUrl="someSASurl") will work, as updating the sasURL sets DIAGNOSTICS_AZURETABLESASURL in appsettings.
我们该如何更改?我是在Powershell中完成的.我首先尝试使用cmdlet Get-AzureRmWebApp,但找不到我想要的东西-旧的Get-AzureWebSite确实显示了AzureTableTraceEnabled,但我无法更新它(也许有更多powershell \ azure经验的人可以输入有关如何使用ASM cmdlet来执行此操作.
How do we change this? I did it in Powershell. I first tried the cmdlet Get-AzureRmWebApp, but could not find what i wanted - the old Get-AzureWebSite does display AzureTableTraceEnabled, but I could not get it to update (perhaps someone with more powershell\azure experience can come with input on how to use the ASM cmdlets to do this).
最适合我的解决方案是通过Set-AzureRmResource命令使用以下设置来设置属性:
The solution that worked for me was setting the property through the Set-AzureRmResource command, with the following settings:
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName "$ResourceGroupName" -ResourceType Microsoft.Web/sites/config -ResourceName "$ResourceName/logs" -ApiVersion 2015-08-01 -Force
$ PropertiesObject如下所示:
Where the $PropertiesObject looks like this:
$PropertiesObject = @{applicationLogs=@{azureTableStorage=@{level="$Level";sasUrl="$SASUrl"}}}
级别对应于错误",警告",信息",详细"和关闭".
The Level corresponds to "Error", "Warning", "Information", "Verbose" and "Off".
也可以在ARM模板中执行此操作(重要的位在站点的日志资源中的属性中):
It is also possible to do this in the ARM Template (important bits is in properties on the logs resource in the site):
{
"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-如何我是从存储帐户中获取访问密钥,以便稍后在模板中的AppSettings中使用的吗?):
The issue with doing it in ARM is that I've yet to find a way to generate the correct SAS, it is possible to fetch out Azure Storage Account keys (from: 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/).
There are also some clever ways of generating them using linked templates (from: http://wp.sjkp.dk/service-bus-arm-templates/).
我所寻求的当前解决方案(时间限制)是一个自定义的Powershell脚本,看起来像这样:
The current solution I went for (time constraints) was a custom Powershell script that looks something like this:
...
$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模板时(或者对于比这更聪明的人都可以使用)我来启发我们).
This is quite an ugly solution, as it is something extra you need to maintain in addition to the ARM template - but it is easy, fast and it works while we wait for updates to the ARM Templates (or for someone cleverer than I to come and enlighten us).
这篇关于为什么不能将Azure诊断配置为通过新的Azure门户使用Azure表存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!