title: Logging Polly wait and retry policy ASP.NET CORE 2.1
body: <p>I need to log retry policy defined via Polly in APS.NET CORE 2.1+. </p>
  
  <p>My code is below showing Polly retry polly and using HttpClient.</p>
  
  <pre><code>public IServiceProvider ConfigureServices(IServiceCollection services)
          {
            //...
  
              //https://github.com/App-vNext/Polly/wiki/Polly-and-HttpClientFactory            
              Random jitterer = new Random();
              services.AddHttpClient&lt;SimpleCastClient&gt;()
                  //TransientErrors:
                  //Network failures(System.Net.Http.HttpRequestException)
                  //HTTP 5XX status codes(server errors)
                  //HTTP 408 status code(request timeout)
                  .AddTransientHttpErrorPolicy(policyBuilder =&gt;
                      //Exponential backoff with Randomisation
                      policyBuilder.WaitAndRetryAsync(10,
                          retryAttempt =&gt; TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                                          + TimeSpan.FromMilliseconds(jitterer.Next(1, 100))
                      ));
  }
  
    [ApiVersion("1")]
      [Route("api/v{version:apiVersion}/[controller]")]
      [ApiController]
      public class MyController : ControllerBase
      {
          ILog _logger;
          private SimpleCastClient _simpleCastClient;
  
          public MyController(ILog logger, SimpleCastClient simpleCastClient)
          {
              _logger = logger;
              _simpleCastClient = simpleCastClient;
          }
  
          [HttpPost]
          public async Task Post()
          {           
              await _simpleCastClient.PostAsync();
  
          }
  
      }
  
  
    public class SimpleCastClient
      {
          private HttpClient _client;
  
          public SimpleCastClient(HttpClient client)
          {
              _client = client;
  
          }
          public async Task PostAsync()
          {
              string url = $"http://localhost:1111/api/v1/Mock/";
              using (var content = new StringContent("data", Encoding.UTF8, "application/json"))
              {                
                  var response = await _client.PostAsync(url, content);                          
              }
          }
  }
  </code></pre>
  
  <p>I wonder if there is a better way than what is on <a href="https://www.stevejgordon.co.uk/passing-an-ilogger-to-polly-policies" rel="noreferrer">stevejgordon</a>.</p>