-1

I have complex hierarchal setting in my appsetting. when I deploy(using Publish) my App from Visual studio, I am wondering if it does copy the appsetting to Azure, because i am getting error related to one of the setting not being available on azure but present in appsetting.

Do i have to manually create all setting again in Azure App Service. Also since Azure App service is Key value pair, how do I accommodate hierarchal settings ?

{
  "ConnectionStrings": {
    "DatabaseConsString": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

  },
  "ApplicationInsights": {
    /*XXXXXXXXXXXXXXX*/
    "InstrumentationKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXX"
  },
  "RedisCache": {
    "ConnectionString": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  },
  "sendGrid": {
    "ApiKey": "SG.XXXXXXXXXXXXXXXXXX",
    "FromEmail": "XXXXXXXX@XXXXXXXXXX.net",
    "FromEmailName": "XXXXXXXXXXXXXXXX"
  },
  "Twilio": {
    "AccountSID": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "AuthToken": "XXXXXXXXXXXXXXXXXXXXXXXXX",
    "FromNumber": "+XXXXXXXX"
  },
  "Jwt": {
    "key": "MyApplicationKey",
    "Issuer": "MyAppName",
    "Audience": "MyAppAudience"
  },
  "Serilog": {
    "Properties": {
      "ApplicationName": "XXXXXXXXXXXXXXXXXXXXXX",
      "Serilog": "AppInsightFromSerilog"   
    },
    "MinimumLevel": { //https://docs.datalust.co/v2/docs/logging-levels  (Verbose,Debug,Information,Warning,Error,Fatal)
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "Using": [ "XXXXXXXXXXXX.Server", "Serilog.Sinks.ApplicationInsights", "Serilog.Sinks.Console" ],
    "Enrich": [
      "FromLogContext",
      "WithUserName",
      "WithIPAddress"
    ],

    "Filter": [
      {
        "Name": "ByExcluding",
        "Args": {
          "expression": "RequestPath like '%swagger%'  or RequestPath like '%_framework%' or Contains(@m, 'Hosting environment:')  or Contains(@m, 'Now listening on:') or Contains(@m, 'HTTP') or Contains(@m, 'Application started. Press Ctrl+C to shut down.') or Contains(@m, 'Content root path:')"
          //https://github.com/serilog/serilog-expressions
        }
      }
    ],
    "WriteTo": [
      {
        "Name": "Console"
        //"Args": {
        //  "levelSwitch": "$consoleSwitch"
        //}
      },
      //{
      //  "Name": "File",
      //  "Args": {
      //    "path": "./logs/log-.txt",
      //    "rollingInterval": "Day"
      //  }
      //},
      {
        "Name": "ApplicationInsights",
        "Args": {
          "restrictedToMinimumLevel": "Information",
          "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights"
        }
      },
      {
        "Name": "MSSqlServer",
        "Args": {
         
          "connectionString": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
          "sinkOptionsSection": {
            "tableName": "SeriLog",
            "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact",
            "schemaName": "dbo",
            "autoCreateSqlTable": true
          },
          "columnOptionsSection": {
            //https://github.com/serilog/serilog-sinks-mssqlserver#custom-property-columns
            "additionalColumns": [
              {
                "ColumnName": "InstanceId",
                "PropertyName": "InstanceId",
                "DataType": "varchar",
                "DataLength": 80
              },
              {
                "ColumnName": "ConnectionId",
                "PropertyName": "ConnectionId",
                "DataType": "varchar",
                "DataLength": 80
              },
              {
                "ColumnName": "RequestId",
                "PropertyName": "RequestId",
                "DataType": "varchar",
                "DataLength": 80
              },
              {
                "ColumnName": "ActionId",
                "PropertyName": "ActionId",
                "DataType": "varchar",
                "DataLength": 80
              },
              {
                "ColumnName": "OperationId",
                "PropertyName": "OperationId",
                "DataType": "varchar",
                "DataLength": 80
              },
              {
                "ColumnName": "ActionName",
                "PropertyName": "ActionName",
                "DataType": "varchar",
                "DataLength": 5000
              },
              {
                "ColumnName": "EnvironmentName",
                "PropertyName": "EnvironmentName",
                "DataType": "varchar",
                "DataLength": 50
              },
              {
                "ColumnName": "ApplicationName",
                "PropertyName": "ApplicationName",
                "DataType": "varchar",
                "DataLength": 5000
              },
              {
                "ColumnName": "UserName",
                "PropertyName": "UserName",
                "DataType": "varchar",
                "DataLength": 1000
              },
              {
                "ColumnName": "IPAddress",
                "PropertyName": "IPAddress",
                "DataType": "varchar",
                "DataLength": 50
              },
              {
                "ColumnName": "Source",
                "PropertyName": "Source",
                "DataType": "varchar",
                "DataLength": 50
              },
              {
                "ColumnName": "SourceContext",
                "PropertyName": "SourceContext",
                "DataType": "varchar",
                "DataLength": 1000
              },
              {
                "ColumnName": "Origin",
                "PropertyName": "Origin",
                "DataType": "varchar",
                "DataLength": 100
              },
              {
                "ColumnName": "OperationType",
                "PropertyName": "OperationType",
                "DataType": "varchar",
                "DataLength": 1000
              },
              {
                "ColumnName": "RequestPath",
                "PropertyName": "RequestPath",
                "DataType": "varchar",
                "DataLength": 1000
              },
              {
                "ColumnName": "MethodName",
                "PropertyName": "MethodName",
                "DataType": "varchar",
                "DataLength": 1000
              }
            ],
            "addStandardColumns": [ "LogEvent" ],
            "removeStandardColumns": [ "MessageTemplate", "Properties" ],
            "logEvent": {
              "excludeAdditionalProperties": true,
              "excludeStandardColumns": true
            }
          },
          "restrictedToMinimumLevel": "Information" // (Verbose,Debug,Information,Warning,Error,Fatal)
        }

      }
    ]
  },
  "AllowedHosts": "*"

}
NSS
  • 1,835
  • 2
  • 29
  • 66

1 Answers1

0

There is no way to directly add your appsettings.json file values in app service application settings/connection settings.

Instead you can use the below ways to achieve this by after deploying it into azure. Refer here

When you deploy your webapp to Azure App Services, usually appsettings.json is not deployed. So you have to use Azure Portal Application Settings blade to upload your settings. In Azure App Services, you can use either use Application Settings or Connection Strings. If you save in the Connection String, you have to use GetConnectionString() API.

In azure Application Settings blade click the Advanced edit button. When finished, click Update. Don't forget to click Save back in the Configuration page.

Make sure your json file format should be in below format

[
    {
        "name": "<key-1>",
        "value": "<value-1>",
        "slotSetting": false
    },
    {
        "name": "<key-2>",
        "value": "<value-2>",
        "slotSetting": false
    },
    ...
]

By using CLI we can add the multiple application settings to your web app service

For adding Single appsetting value

az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings <setting-name>="<value>"

For adding the appsettings value using .json file

az  webapp  config  appsettings  set  --resource-group <resource-group-name>  --name <app-name>  --settings  mySetting=value  "@moresettings.json"

Refer here

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15