如何在 VS Code 中禁用 HTTP 请求的日志记录

时间:2021-07-20 18:59:53

标签: asp.net-core logging visual-studio-code

如何禁用或隐藏 HTTP 请求的日志记录。当我运行我的应用程序时,Debug Console 充满了信息日志,如下所示:

info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action MyApp.Controllers.HomeController.Index (MyApp) in 128.658ms
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action MyApp.Controllers.HomeController.Index (MyApp) in 128.658ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 356.7146ms 200 text/html; charset=utf-8
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 356.7146ms 200 text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:5000/lib/bootstrap/dist/css/bootstrap.css  
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:5000/css/site.css  

1 个答案:

答案 0 :(得分:1)

您需要为您的程序设置yes,如果您在本地环境中运行您的程序,您最好修改appsettings.Development.json而不是appsettings.json

根据您的片段,我认为将日志级别修改为警告可以实现您的目标。下面是我的配置和添加配置前后的测试结果。如果你只想隐藏那些包含 http 请求的信息,你也可以使用 "Microsoft.AspNetCore.Hosting": "Warning" 而不是 "Microsoft": "Warning"

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    },
    "Console": {
      "IncludeScopes": true,
      "LogLevel": {
        "Microsoft": "Warning"
      }
    }
  }
}

log level enter image description here