appsettings.json 中 IncludeScopes 的 JSON 验证失败

Posted

技术标签:

【中文标题】appsettings.json 中 IncludeScopes 的 JSON 验证失败【英文标题】:JSON validation failed for IncludeScopes in appsettings.json 【发布时间】:2021-11-09 05:13:04 【问题描述】:

我正在使用 ASP.NET Core 2.1。

为什么我的appsettings.json 文件中的IncludeScopes 会出现Expression must be of type object

这是显示警告所需的 JSON 的简化版本。 要重现这一点,您只需要创建一个空白的 ASP.NET Core 项目并更新 appsettings.json:


  "Logging": 
    "IncludeScopes": false,
    "Debug": 
      "LogLevel": 
        "Default": "Warning"
      
    ,
    "Console": 
      "LogLevel": 
        "Default": "Warning"
      
    
  ,
  "serilog": 
    "write-to": 
      "sumologic.url": "http://localhost",
      "RollingFile.pathFormat": "R\\Document\\API\\Logs-Date.log"
    
  

【问题讨论】:

嗨@David Klempfner,请分享足够的代码来重现您的问题。也请分享 json 而不是截图。 @Rena 感谢您的反馈。我已经更新了问题。 嗨@David Klempfner,我明白了。请在下面查看我的答案。 【参考方案1】:

正如the github issue 所说,您将IncludeScopes 添加到错误的级别。如下更改:


  "Logging": 
    "Console": 
      "LogLevel": 
        "Default": "Warning"
      ,
      "IncludeScopes": false
    ,
    "Debug": 
      "LogLevel": 
        "Default": "Warning"
      
    
    
  ,
  "serilog": 
    "write-to": 
      "sumologic.url": "http://localhost",
      "RollingFile.pathFormat": "R\\Document\\API\\Logs-Date.log"
    
  
 

【讨论】:

以上是关于appsettings.json 中 IncludeScopes 的 JSON 验证失败的主要内容,如果未能解决你的问题,请参考以下文章

(新格式)Visual Studio 项目中的可选 appsettings.local.json

ASP.NET Core appsettings.json 文件

从不同项目访问 appsettings.json

从 .NET Core 2 中的类中读取 appsettings.json

在 EF 上下文中使用 appsettings.json 配置

如何在 .NET Core MVC 项目中转换 appsettings.json?