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.
Flurl stands for the Fluent URL. Quoting Flurl's home page: Flurl is a modern, fluent, asynchronous, testable, portable, buzzword-laden URL builder and HTTP client library for . NET. It's simple as that.
FlurlClient is a lightweight wrapper around HttpClient and is tightly bound to its lifetime. It implements IDisposable , and when disposed will also dispose HttpClient . FlurlClient includes a BaseUrl property, as well as Headers , Settings , and many of the fluent methods you may already be familiar with.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With