在ASP.NET Core中删除HTTP客户端日志记录处理程序 [英] Remove http client logging handler in ASP.NET Core

查看:149
本文介绍了在ASP.NET Core中删除HTTP客户端日志记录处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用.NET Core的HttpClientFactory时,是否可以通过某种方式删除默认的LoggingHttpMessageHandler?

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>();

推荐答案

对于任何需要此解决方案的人,我已经在github存储库上打开了一个问题,其中一个贡献者回答了以下问题(我仍然需要尝试一下) tho)

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

这篇关于在ASP.NET Core中删除HTTP客户端日志记录处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆