You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
using Flurl;
|
|
using Flurl.Http.Configuration;
|
|
using Serilog;
|
|
|
|
namespace TrashLib.Extensions;
|
|
|
|
public static class FlurlLogging
|
|
{
|
|
public static void SetupLogging(FlurlHttpSettings settings, ILogger log, Func<Url, Url>? urlInterceptor = null)
|
|
{
|
|
urlInterceptor ??= url => url;
|
|
|
|
settings.BeforeCall = call =>
|
|
{
|
|
var url = urlInterceptor(call.Request.Url.Clone());
|
|
log.Debug("HTTP Request: {Method} {Url}", call.HttpRequestMessage.Method, url);
|
|
};
|
|
|
|
settings.AfterCall = call =>
|
|
{
|
|
var statusCode = call.Response?.StatusCode.ToString() ?? "(No response)";
|
|
var url = urlInterceptor(call.Request.Url.Clone());
|
|
log.Debug("HTTP Response: {Status} {Method} {Url}", statusCode, call.HttpRequestMessage.Method, url);
|
|
};
|
|
|
|
settings.OnRedirect = call =>
|
|
{
|
|
log.Warning("HTTP Redirect received; this indicates a problem with your URL and/or reverse proxy: {Url}",
|
|
call.Redirect.Url);
|
|
|
|
call.Redirect.Follow = false;
|
|
};
|
|
}
|
|
}
|