I'm using Polly to retry HttpClient attemnpts :
services.AddHttpClient<JoinPackageApiClient>(jp => { jp.BaseAddress = new Uri(appSettings.JoinPackageWS.BaseUrl); })
.AddPolicyHandler(GetRetryPolicy(appSettings, serviceProvider))
Where GetRetryPolicy
is :
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy(AppSettings appSettings, ServiceProvider serviceProvider)
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode != HttpStatusCode.OK)
.Or<TimeoutRejectedException>()
.Or<TaskCanceledException>()
.Or<OperationCanceledException>()
.WaitAndRetryAsync(appSettings.PollySettings.RetryAttempts, (retryAttempt, c) =>
{
return TimeSpan.FromSeconds(2);
}, onRetry: (response, delay, retryCount, context) =>
{
//█how can I access the full(!) HttpClient's URI here ?
//e.g. : https://a.com/b/c?d=1
});
}
Question:
Looking at the onRetry
parameter, I want to log the full URL attempt in the onRetry
section.
How can I get the full URI in that section ?