Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Polly RetryAsync不工作,代码未记录_C#_Xamarin_Polly - Fatal编程技术网

C# Polly RetryAsync不工作,代码未记录

C# Polly RetryAsync不工作,代码未记录,c#,xamarin,polly,C#,Xamarin,Polly,我正在尝试使用异步策略处理所有401响应 一些注意事项: 我正在使用Xamarin.Forms 我正在使用重新安装,但没有HttpClientFactory 以下是重试策略: var unauthorizedPolicy=Policy.Handle 从日志中可以看到,令牌已成功检索,但我认为在重试调用时使用了旧令牌。我不能确定,因为电话不再记录 这就引出了我的第二个问题,有没有办法记录和调试Polly重试的每个HTTP调用 从日志中可以看到,令牌已成功检索,但我认为在重试调用时使用了旧令牌。

我正在尝试使用异步策略处理所有401响应

一些注意事项:

  • 我正在使用Xamarin.Forms
  • 我正在使用重新安装,但没有HttpClientFactory
以下是重试策略:

var unauthorizedPolicy=Policy.Handle

从日志中可以看到,令牌已成功检索,但我认为在重试调用时使用了旧令牌。我不能确定,因为电话不再记录

这就引出了我的第二个问题,有没有办法记录和调试Polly重试的每个HTTP调用

从日志中可以看到,令牌已成功检索,但我认为在重试调用时使用了旧令牌。我不能确定,因为电话不再记录

代码只进行了一次调用:

var task = SomeMethodNotShownAsync();
result = await _taskManager._defaultPolicyForHttpRequests // the above defined unauthorizedPolicy
    .ExecuteAndCaptureAsync<T>(async () => await task)
    .ConfigureAwait(false);
有没有办法记录和调试Polly重试的每个HTTP调用

已经是了。:)一次呼叫只有日志消息的原因是因为只有一次呼叫

var task = SomeMethodNotShownAsync();
result = await _taskManager._defaultPolicyForHttpRequests // the above defined unauthorizedPolicy
    .ExecuteAndCaptureAsync<T>(async () => await task)
    .ConfigureAwait(false);
ExecuteAndCaptureAsync<T>(async () => await task)
result = await _taskManager._defaultPolicyForHttpRequests // the above defined unauthorizedPolicy
    .ExecuteAndCaptureAsync<T>(async () => await SomeMethodNotShownAsync())
    .ConfigureAwait(false);