Replies: 4 comments 1 reply
-
Well, it depends. Are you the one who is calling the If you can provide an example how do you plan to define and use the retry strategy then I can provide some suggestions. |
Beta Was this translation helpful? Give feedback.
-
I'm defining the pipeline like this:
And starting the execution like this:
By the way, I'm not really sure whether it is better to use the |
Beta Was this translation helpful? Give feedback.
-
In this particular scenario, you can use the following two options:
Option 1Your current code declares the 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 RetryStrategyOptions
{
...
OnRetry = args =>
{
...
this.logger....
return default;
},
})
.Build();
}
...
} Option 2You can pass the logger to the strategy execution in the exact same way as you did with the resilienceContext.Properties.Set(ResilienceContextKeys.Logger, logger);
...
if(args.Context.Properties.TryGetValue(ResilienceContextKeys.Logger, out var logger)) Side notes
services.AddResiliencePipeline("my-key", (builder, context) =>
{
var loggerFactory = context.ServiceProvider.GetRequiredService<ILoggerFactory>();
builder.AddRetry(...);
}); |
Beta Was this translation helpful? Give feedback.
-
Thanks, @peter-csala, I'll probably try Option 1 or just use the DI. |
Beta Was this translation helpful? Give feedback.
-
Hello,
What is the idiomatic way of passing an ILogger to the
OnRetry
delegate? Samples conveniently show usingConsole.WriteLine
, which is, of course, not feasible in production.Thank you
Beta Was this translation helpful? Give feedback.
All reactions