Search code examples
c#blazorblazor-webassembly

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?


Solution

  • 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