Skip to content

Logging in OnRetry #2070

Closed Answered by peter-csala
mickvikt asked this question in Q&A
Apr 23, 2024 · 4 comments · 1 reply
Discussion options

You must be logged in to vote

In this particular scenario, you can use the following two options:

  • Access directly an ILogger inside the OnRetry delegate
  • Use the context to "attach" an ILogger to the strategy execution

Option 1

Your current code declares the resiliencePipeline as readonly and defines its value at the same time. If you could define its value inside a constructor then you can refer the ILogger without the need to use closure:

class XYZ
{
   private readonly ILogger<XYZ> logger;
   private readonly ResiliencePipeline resiliencePipeline;
   
   public XYZ(ILogger<XYZ> logger)
   {
      this.logger = logger;
      this.resiliencePipeline = new ResiliencePipelineBuilder()
        .AddRetry(new RetryStrate…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by martintmk
Comment options

You must be logged in to vote
1 reply
@peter-csala
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants