Disable HttpClient logging in .NET
Codemia Knowledge Hub ·
Set the log level for the System.Net.Http.HttpClient category to None. In .NET, HttpClient activity goes through the built-in logging framework, so you control it with logging configuration: appsettings.json, an environment variable, or a filter in code.
Turning it down is worth it because logging every request adds overhead under high load, requests often contain sensitive data that logs can expose, and the volume clutters logs and buries important diagnostics.
Set the log level in appsettings.json
In ASP.NET Core, logging is usually configured in appsettings.json. Lower the level for HttpClient or disable it entirely:
Set it with an environment variable
To change the level without touching code or configuration files, set an environment variable named Logging__LogLevel__System.Net.Http.HttpClient to None. The double underscores stand for the : separators, and the periods stay because they are part of the category name, so some shells need env or a similar tool to export it.
Add a filter in code
You can also configure logging in code when you register services, often in Startup.cs:
Log selectively with a custom DelegatingHandler
Instead of disabling logging entirely, write a handler that decides what to log:
Attach it to your HttpClient instance. A handler created by hand needs an InnerHandler to pass the request on, or the first request throws InvalidOperationException:
Keep detailed logs where you need them
- Debugging: disabling logging completely can make debugging harder, especially in development.
- Per environment: disable logging in production and keep detailed logs in development or staging.
- Granularity: aim to keep the information you need while dropping excessive entries. Make changes incrementally and test their impact.
- Log access: restrict access to any remaining logs to authorized people.
- Review regularly: revisit logging configuration as the application scales and changes.
| Aspect | Explanation |
| Performance | Disabling unnecessary logs reduces application overhead. |
| Security | Prevent logging of sensitive request and response data. |
| Configuration | Can be adjusted via appsettings.json, environment variables, or programmatically. |
| Custom Handlers | Use custom handlers to gain fine control over what is specifically logged. |
| Balanced Approach | Find a balance that suits both development and production needs. |
| Environment Specific | Tailor logging configurations for different environments (dev, staging, prod). |
Related reading
- Disable Logback in SpringBoot
- Disabling network logs on Kubernetes when running kubectl exec
- Disadvantages of using eureka for Service Discovery with kubernetes
- Distribute children elements or the top-level parent elements among monitoring hosts
- Disconnect client session from Spring websocket stomp server
- Distributed Erlang and the CAP theorem
- Disable JavaScript error in WebBrowser control
- Disable SSL fallback and use only TLS for outbound connections in .NET? Poodle mitigation
System design interview problems on this topic
- Design a Metrics Monitoring and Alerting System: solution and walkthrough
- Design a Distributed Tracing System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.