Asp.NET core logs each request that enters based on configuration. Now i'd like to have the same functionality for Flurl requests i sent. Most notably, I of course would like to know when a requests fails or does not complete. For debugging I found logging all requests in a verbose matter was extremely helpful.
Asked
Active
Viewed 4,027 times
1 Answers
10
Sure can. For cross-cutting concerns like logging, you want to use Flurl's event handlers, specifically BeforeCall
, AfterCall
, OnError
, and their async equivalents (BeforeCallAsync
, AfterCallAsync
, OnErrorAsync
). Here's an error logging example:
private async Task HandleFlurlErrorAsync(HttpCall call)
{
await LogErrorAsync(call.Exception.Message);
call.ExceptionHandled = true; // prevents exception from bubbling up, if desired
}
// Configure once at startup:
FlurlHttp.Configure(settings => settings.OnErrorAsync = HandleFlurlErrorAsync);

3dGrabber
- 4,710
- 1
- 34
- 42

Todd Menier
- 37,557
- 17
- 150
- 173
-
2How to inject logger object in OnErrorAsync using .NET Core? – Tomas Sep 27 '22 at 15:20