Remove http client logging handler in ASP.NET Core

瘦欲@ 提交于 2020-12-05 12:49:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!