Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In my Blazor WebAssembly client, I have this 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?

like image 745
Patrick Szalapski Avatar asked Mar 03 '23 01:03

Patrick Szalapski


2 Answers

In a .NET 5 latest version in case you don't want those to be shown on blazor client side, you can do this in your Main method of startup class.

builder.Logging.SetMinimumLevel(LogLevel.None);
like image 69
J S Avatar answered Mar 04 '23 14:03

J S


using Microsoft.Extensions.Logging;

...

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

You have to configure the logger in the builder.

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

like image 26
rabz100 Avatar answered Mar 04 '23 13:03

rabz100