Skip to content

Modify HttpClientFactory based HttpClient request logging #44411

@johnkors

Description

@johnkors

Hi,

I saw this issue for overriding the default logging / altering the log statements emitted when doing requests using a HttpClientFactory based HttpClient, which recommends re-implementing the IHttpMessageHandlerBuilderFilter for this.

I wanted 2 alterations from the default logging, to reduce the logs:

  1. Don't emit 2 log statements for each request, but only one (the default logging emits a start-req, and a end-req log statement)
  2. In the single emitted log statement, include the request url.

So reducing this:

- "Sending HTTP request {HttpMethod} {Uri}");
- "Received HTTP response headers after {ElapsedMilliseconds}ms - {StatusCode}"

to

- $"{HttpMethod} {Uri} - {StatusCode} in {ElapsedMilliseconds}ms"

I was surprised by the amount of code I had to write to be able to do this. Is there no easier way to just modify the default log statements..?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions