Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off HttpClient Logging in .net core 3.1 [duplicate]

When using the HttpClientFactory of .NET Core, is it possible to somehow remove the default LoggingHttpMessageHandler?

I expect something like the below but it doesn't seem to exists

services.AddHttpClient("minos")
   .RemoveHttpMessageHandler<LoggingHttpMessageHandler>();
like image 481
Stephen Lautier Avatar asked Jan 31 '26 11:01

Stephen Lautier


1 Answers

Just for anyone needing this, I had opened an issue on the GitHub repo, and one of the contributors had replied with the following

services.RemoveAll<IHttpMessageHandlerBuilderFilter>();
  1. Just Add this line AFTER the adding of the HttpClient
  2. Make sure to use Microsoft.Extensions.DependencyInjection.Extensions namespace

https://github.com/aspnet/HttpClientFactory/issues/196#issuecomment-432755765

like image 123
Stephen Lautier Avatar answered Feb 02 '26 00:02

Stephen Lautier