ARM模板 - 配置诊断日志

时间:2017-10-27 13:42:35

标签: azure-web-sites

我尝试使用ARM模板在应用服务上配置一些诊断日志。虽然某些配置已正确应用于模板,但某些配置属性(如retentionInDays和sasUrl(用于blob存储))未应用。

我基本上使用这种格式:

          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Information"
              },
              "azureTableStorage": {
                "level": "Off",
                "sasUrl": null
              },
              "azureBlobStorage": {
                "level": "Verbose",
                "sasUrl": "[variables('mySasUrl')]",
                "retentionInDays": 1,
                "enabled": true
              }
            },
            "httpLogs": {
              "fileSystem": {
                "retentionInMb": 50,
                "retentionInDays": 1,
                "enabled": true
              },
              "azureBlobStorage": {
                "sasUrl": null,
                "retentionInDays": 1,
                "enabled": false
              }
            },
            "failedRequestsTracing": {
              "enabled": true
            },
            "detailedErrorMessages": {
              "enabled": true
            }

主要跟随this示例,但是使用blob存储设置扩展它。部分拾取了azureBlobStorage设置(正确应用了级别),但正如我所说,不应用sasUrl和retentionInDays。任何人都有这个工作?

3 个答案:

答案 0 :(得分:1)

根据你的描述和提供的链接,我已经在我身边创建了一个测试演示。它运行良好。

我猜你可能会设置错误的blob SAS网址。我建议你可以生成一个容器级SAS网址,然后再试一次。

SAS格式如下:

https://{yourstorageaccount}.blob.core.windows.net/mycontainer?sv=2015-04-05&sr=c&sig={sig}&st=2017-10-30T02:09:57Z&se=2217-10-30T02:09:57Z&sp=rwdl

有关mt测试模板的更多详细信息,请参阅以下代码:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "brandosptestName": {
      "type": "string",
      "minLength": 1
    },
    "brandosptestSkuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    }
  },
  "variables": {
    "bandotestName": "[concat('bandotest', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "name": "[parameters('brandosptestName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "sku": {
        "name": "[parameters('brandosptestSkuName')]"
      },
      "dependsOn": [ ],
      "tags": {
        "displayName": "brandosptest"
      },
      "properties": {
        "name": "[parameters('brandosptestName')]",
        "numberOfWorkers": 1
      }
    },
    {
      "name": "[variables('bandotestName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "resources": [
        {
          "name": "logs",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites',variables('bandotestName'))]"
          ],
          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Off"
              },
              "azureTableStorage": {
                "level": "Off",
                "sasUrl": null
              },
              "azureBlobStorage": {
                "level": "Verbose",
                "sasUrl": "url",
                "retentionInDays": 7
              },
              "httpLogs": {
                "fileSystem": {
                  "retentionInMb": 35,
                  "retentionInDays": 7,
                  "enabled": false
                },
                "azureBlobStorage": {
                  "sasUrl": "url",
                  "retentionInDays": 7,
                  "enabled": true
                }
              },
              "failedRequestsTracing": {
                "enabled": false
              },
              "detailedErrorMessages": {
                "enabled": false
              }
            }
          }
        }
      ],

      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('brandosptestName'))]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', parameters('brandosptestName')))]": "Resource",
        "displayName": "bandotest"
      },
      "properties": {
        "name": "[variables('bandotestName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('brandosptestName'))]"
      }
    }
  ],
  "outputs": {
  }
}

结果:

enter image description here

答案 1 :(得分:0)

我认为您的问题在于您的SAS URI的生成。这是文档的链接:https://docs.microsoft.com/en-us/azure/storage/common/storage-dotnet-shared-access-signature-part-1#examples-of-sas-uris

很难确切地找到如何为您的URL生成签名,但是使用Azure PowerShell CLI工具使其变得简单:

  1. 获取您的存储帐户资源: $storage = Get-AzureRmStorageAccount -ResourceGroupName "<resource-group-name>" -AccountName "<storage-account-name>";
  2. 如果您还没有容器,请创建一个: New-AzureStorageContainer -Name "<your-blob-storage-container-name>" -Context $storage.Context -Permission Off;
  3. 生成您的SAS URI: Write-Host (New-AzureStorageContainerSASToken -Name "<your-blob-storage-container-name>" -Permission rw -Context $storage.Context -StartTime (Get-Date) -ExpiryTime (Get-Date).AddYears(100) -FullUri);

请注意,对于每个容器,您需要生成一个URI。

答案 2 :(得分:0)

应用服务器记录您在帖子中显示的ARM属性格式正确。

您在OP中提到的症状(某些配置已正确应用到模板,某些配置属性(例如,remainingInDays和sasUrl(用于Blob存储)未应用)通过ARM模板配置appSettings和日志时,可能会发生这种情况。

当您通过Azure资源管理器应用sasUrl时,它将在您的配置中创建以下appsettings项

  • DIAGNOSTICS_AZUREBLOBCONTAINERSASURL
  • DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS

随后,当ARM应用您的appSettings时,它将重置所有设置为Off(除去所需的配置),并使用ARM模板“ appSettings”部分中提到的值重置appSettings。这会导致您注意到行为不一致。

将依赖项添加到日志资源,以便在appSettings之后通过通过dependsOn引入依赖项来执行 "[resourceId('Microsoft.Web/sites/config', variables('webAppName'), 'appsettings')]"

我在Configure app and web server logs to a storage account in ARM template

上写了详细的帖子