I'm trying to set up Polly in .Net Core 3.1 (Azure Functions v3).
I want to create a Policy in the Startup class which I can inject into functions.
The behaviour that I'm looking for is: It should wait And retry 3 times - if the final try fails - it should catch and log the exception (Serilog) otherwise just continue.
At the moment I have the following piece of code:
AsyncRetryPolicy emailRetryPolicy = Policy.Handle<Exception>()
.WaitAndRetryAsync(3, retryAttempt =>
TimeSpan.FromMilliseconds(retryAttempt * 500));
As you see I miss the part where it logs the error after 3 tries - and just continue. Any Idea how to do that?
Serilog is also added in Startup class (Partial code shown)
builder.Services.AddLogging(al => al.AddSerilog(logger));
I'm going to send an email with MailKit and want to log if it for some reasons fails. It should not stop the program for running.