且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

包含Web应用程序配置设置的ARM模板

更新时间:2023-11-20 21:16:34

我尝试使用appsetting和日志创建WebApp,它对我来说正常工作.我使用Visual Studio创建了该项目.以下是我的详细步骤.

I try to create WebApp with the appsetting and logs, it works correctly for me. I created the project using Visual Studio. The following is my detail steps.

1.创建Azure资源项目

1.Create the Azure Resource Project

2.选择WebApp模板

2.Select the WebApp template

3.单击部署文件,然后右键单击并删除不必要的资源

3.Click the deploy file then right click and remove the unnecessary resource

4.为WebApp添加Appsetting资源

4.Add the Appsetting Resource for the WebApp

5.添加Azure WebApp的日志代码

5.Add the logs code for the Azure WebApp

{
          "apiVersion": "2015-08-01",
          "name": "logs",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Off"
              },
              "azureTableStorage": {
                "level": "Off"
              },
              "azureBlobStorage": {
                "level": "[variables('Level')]",
                "sasUrl": "xxxx"
              }
            },
            "httpLogs": {
              "fileSystem": {
                "enabled": false
              },
              "azureBlobStorage": {
                "enabled": true,
                "sasUrl": "xxxxxx"
              }
            },
            "failedRequestsTracing": {
              "enabled": "[parameters('enableFailedRequestTracing')]"
            },
            "detailedErrorMessages": {
              "enabled": "[parameters('enableDetailedErrorMessages')]"
            }
          }
        }

6.右键单击项目,然后选择部署

6.Right click the project and select the deploy

7.从Output and Azure门户检查结果

7.Check the result from the Output and Azure portal

整个手臂模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "enableFailedRequestTracing": {
      "type": "bool"
    },
    "enableDetailedErrorMessages": {
      "type": "bool"
    },
    "skuName": {
      "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/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]",
    "Level": "Error"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]"
          ],
          "tags": {
            "displayName": "appsettings"
          },
          "properties": {
            "key1": "value1",
            "key2": "value2"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "logs",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Off"
              },
              "azureTableStorage": {
                "level": "Off"
              },
              "azureBlobStorage": {
                "level": "[variables('Level')]",
                "sasUrl": "xxxxx"
              }
            },
            "httpLogs": {
              "fileSystem": {
                "enabled": false
              },
              "azureBlobStorage": {
                "enabled": true,
                "sasUrl": "xxxx"
              }
            },
            "failedRequestsTracing": {
              "enabled": "[parameters('enableFailedRequestTracing')]"
            },
            "detailedErrorMessages": {
              "enabled": "[parameters('enableDetailedErrorMessages')]"
            }
          }
        }
      ]
    }

  ]
 }