How to reference another value within the same appsettings.json file?

前端 未结 3 1846
一个人的身影
一个人的身影 2021-01-24 00:13

I need database connection string in two places in appsettings.json.

Is it possible to introduce common variable or json-path related references into json file to avoid

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-24 00:44

    NLog has the ability to lookup values in the appsettings.json. You can do it like this with ${configsetting}:

    {
    ...
      "ConnectionStrings": {
        "Default": "Host=localhost;Database=db;Port=5432;Username=postgres;Password=postgres"
      },
      "Nlog": {
        "targets": {
          "database": {
            "type": "Database",
            "dbProvider": "Npgsql.NpgsqlConnection, Npgsql",
            "connectionString": "${configsetting:item=ConnectionStrings.Default}",
    ...
          }
        }
    ...
    }
    

    See also https://github.com/NLog/NLog/wiki/ConfigSetting-Layout-Renderer

提交回复
热议问题