简体   繁体   English

如何从 Blazor 中的 HttpClients 关闭浏览器控制台中的“信息”登录?

[英]How can I turn off "info" logging in browser console from HttpClients in Blazor?

In my Blazor WebAssembly client, I have this appsetting:在我的 Blazor WebAssembly 客户端中,我有这个 appsetting:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

So why do I still get endless cruft in my browser console when running locally?那么为什么在本地运行时,我的浏览器控制台中仍然会出现无尽的问题?

info: System.Net.Http.HttpClient.MyNamedClientName.ClientHandler[101]
      Received HTTP response headers after 190ms - 200 blazor.webassembly.js:1:9737
info: System.Net.Http.HttpClient.MyNamedClientName.LogicalHandler[101]
      End processing HTTP request after 193ms - 200 blazor.webassembly.js:1:9737
info: System.Net.Http.HttpClient.MyNamedClientName.ClientHandler[101]
      Received HTTP response headers after 267ms - 200 blazor.webassembly.js:1:9737
info: System.Net.Http.HttpClient.MyNamedClientName.LogicalHandler[101]
      End processing HTTP request after 274ms - 200 blazor.webassembly.js:1:9737
info: System.Net.Http.HttpClient.MyNamedClientName.ClientHandler[101]
      Received HTTP response headers after 316ms - 200 blazor.webassembly.js:1:9737
info: System.Net.Http.HttpClient.MyNamedClientName.LogicalHandler[101]
      End processing HTTP request after 319ms - 200

How can I turn off these info lines?如何关闭这些信息行?

在 .NET 5 最新版本中,如果您不想在 blazor 客户端显示这些内容,您可以在启动类的 Main 方法中执行此操作。

builder.Logging.SetMinimumLevel(LogLevel.None);
using Microsoft.Extensions.Logging;

...

builder.Logging.AddConfiguration(
    builder.Configuration.GetSection("Logging"));

You have to configure the logger in the builder.您必须在构建器中配置记录器。

Reference: https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/configuration?view=aspnetcore-3.1#logging-configuration参考: https : //docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/configuration?view=aspnetcore-3.1#logging-configuration

如何删除 HttpClient 的日志记录而不是别的:

builder.Services.RemoveAll<IHttpMessageHandlerBuilderFilter>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Blazor 服务器写入浏览器控制台 - How can I write to browser console from Blazor Server 如何关闭日志级别和类别 output 中的 .NET Core 日志记录到 AWS CloudWatch? - How can I turn off log level & category output in .NET Core logging to AWS CloudWatch? 如何关闭customErrors? - How can I turn off customErrors? pinvokestackimbalance——我该如何解决或关闭它? - pinvokestackimbalance -- how can I fix this or turn it off? 我该如何修复以下 nullreference? 以及如何关闭 nullrefernce(来自<propertygroup> )?</propertygroup> - how i can fix following nullrefernce ? and also how can I turn off nullrefernce (from <propertygroup>)? 关闭 ServiceStack 日志记录 - Turn Off ServiceStack Logging 关闭HttpRequestValidationException日志记录? - Turn off HttpRequestValidationException logging? 关闭日志记录和调试 - Turn off logging and debugging 实体框架:我可以在从本地读取时关闭 AutoDetectChangesEnabled 吗? - Entity Framework: can I turn off AutoDetectChangesEnabled on reading from Local? 如何关闭 ASP.NET 和实体框架为每个请求完成的默认日志记录? - How do I turn off the default logging done by ASP.NET and Entity Framework for each request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM