sách gpt4 ai đã đi

Tại sao tôi không thể cấu hình Azure Diagnostics để sử dụng Azure Table Storage thông qua cổng thông tin Azure mới?

In lại 作者:行者123 更新时间:2023-12-04 15:09:22 29 4
mua khóa gpt4 Nike

我正在开发一个将托管在 Azure 中的 Web API。我想使用 Azure 诊断将错误记录到 Azure 表存储中。在经典门户中,我可以将日志配置为转到 Azure 表存储。

Classic Portal Diagnostic Settings

但是,在新的 Azure 门户中,我唯一的存储选项是使用 Blob 存储:

New Azure Portal Settings

看来,如果我要使用 Web 角色,我可以配置用于诊断的数据存储,但由于我正在开发 Web api,我不想为每个 api 创建单独的 Web 角色我可以登录到 azure 的表。

是否有一种方法可以以编程方式配置 azure 诊断以将日志消息传播到特定数据存储,而无需使用 Web 角色?是否有任何原因导致新的 Azure 门户仅具有 Blob 存储而不是表存储的诊断设置?

我目前可以通过使用经典门户来解决该问题,但我担心用于诊断的表存储最终将被弃用,因为它尚未包含在新门户的诊断设置中。

1 Câu trả lời

(我将对这个问题做一些死灵术,因为这是我在寻找解决方案时发现的最相关的 StackOverflow 问题,因为不再可能通过经典门户来做到这一点)

免责声明:微软似乎已经删除了对登录到 Azure 门户中的表的支持,因此我不知道这是否已被弃用或即将被弃用,但我有一个现在可以使用的解决方案(2017 年 3 月 31 日):

有一些特定的设置决定日志记录,我首先从 Azure Powershell github 中的一个问题中找到了这方面的信息:https://github.com/Azure/azure-powershell/issues/317

我们需要的具体设置是(来自github):

AzureTableTraceEnabled = True, & AppSettings has: 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") 将会起作用,因为更新 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 的方法,可以提取 Azure 存储帐户 key (来自: 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 模板更新时它可以工作(或者对于比我来启发我们)。

关于azure - 为什么无法通过新的 Azure 门户配置 Azure 诊断以使用 Azure 表存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006676/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com