将部分添加到appsettings.json会导致崩溃

时间:2017-11-20 13:05:21

标签: c# .net asp.net-mvc

我正在OS X上构建Asp.Net MVC(.Net Core 2.0)应用程序。

appsettings.json修改为:

{
  "AppSettings": {
    Interval":  15
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

构建成功,但执行在WebHost.CreateDefaultBuilder文件的Program.cs行停止:

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .Build();
}

我错过了什么吗?

参考:AppSettings in ASP.NET Core

2 个答案:

答案 0 :(得分:1)

看起来您的appsettings不是有效的JSON。你错过了Interval周围的双引号。尝试

 {
  "AppSettings": {
    "Interval":  15
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

答案 1 :(得分:-1)

您只需遵循此格式即可。

  {
    "Logging": {
       "IncludeScopes": false,
       "LogLevel": {
       "Default": "Warning"
    }
  },
  "Config1": {
      "Key": "value"
   },

 "Config2": {
     "Key1": "value1",
     "key1": "value2"
 }