Skip to content
Discussion options

You must be logged in to vote

Refit has no built-in request logging. Logging is the job of the HttpClient pipeline, so add a DelegatingHandler that logs the request (and body) and plug it in.

Minimal handler:

class LoggingHandler : DelegatingHandler
{
    protected override async Task<HttpResponseMessage> SendAsync(
        HttpRequestMessage request, CancellationToken ct)
    {
        if (request.Content != null)
        {
            var body = await request.Content.ReadAsStringAsync(ct);
            Console.WriteLine($"{request.Method} {request.RequestUri}\n{body}");
        }
        return await base.SendAsync(request, ct);
    }
}

Wire it up with HttpClientFactory:

services.AddRefitClient<IMyApi>()
    .Configu…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by glennawatson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants