Reducing HttpClient Logging in C# Application

If you have an application code written in C# and use HttpClient in the code, you may encounter instances where HttpClient generates a significant amount of logging information, such as:

  • Start processing HTTP request
  • Sending HTTP request
  • Received HTTP response headers after … ms – 200
  • End processing HTTP request after … ms – 200

These logs can be overwhelming and make it difficult to identify and troubleshoot issues. In this blog post, we’ll show you how to adjust the logging levels for HttpClient to reduce the amount of logging information generated by your application.

To remove the logging that you’re seeing in your C# code, you can adjust the logging level for the System.Net.Http.HttpClient namespace in your appsettings.json file. By setting the logging level to Warning or higher, you can prevent the Info level logs from appearing.

Here’s an example of how you can adjust the logging level in your appsettings.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "System.Net.Http.HttpClient": "Warning"
    }
  }
}

In the above example, the logging level for System.Net.Http.HttpClient is set to Warning, which means that only Warning, Error, and Critical level logs will be displayed for that namespace. The Info level logs will no longer appear.

After making these changes, restart your application for the new logging settings to take effect.