问题
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>();
回答1:
Just for anyone needing this, I had opened an issue on the github repo, and one of the contributors had replied with the following (i still need to try it tho)
foreach (var service in serviceCollection.Where(s => s.ServiceType == typeof(IHttpMessageHandlerFactory)))
{
serviceCollection.Remove(service);
}
Update: Use the following instead (the above doesn't work completely)
services.RemoveAll<IHttpMessageHandlerBuilderFilter>();
https://github.com/aspnet/HttpClientFactory/issues/196#issuecomment-431440889
回答2:
You can configure it in appsettings.json by setting HttpClient's log level to none: https://www.stevejgordon.co.uk/httpclientfactory-asp-net-core-logging
来源:https://stackoverflow.com/questions/52889827/remove-http-client-logging-handler-in-asp-net-core