[英]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.