【问题标题】:Track asynchronous Azure operations using the fluent API使用 fluent API 跟踪异步 Azure 操作
【发布时间】:2018-08-30 17:02:25
【问题描述】:

我知道您可以使用标准 API 跟踪正常操作:https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-async-operations

但是我想知道是否有一种已知方法可以利用Fluent Azure Management Libraries 来跟踪长异步操作,例如 VM 操作等。例如,VM 重新启动方法是一个 void Task,它不返回用于跟踪的操作 ID .

async Task IVirtualMachineScaleSetVM.RestartAsync(CancellationToken cancellationToken)
{
  await this.RestartAsync(cancellationToken);
}

干杯!

【问题讨论】:

    标签: azure azure-api-management azure-management-api azure-fluent-api


    【解决方案1】:

    AFAIK,似乎很难跟踪不返回 operationId 的 VM 重启状态。

    登录 .NET 的流畅 Azure 管理库利用底层 AutoRest 服务客户端跟踪。

    创建一个实现Microsoft.Rest.IServiceClientTracingInterceptor 的类。此类将负责拦截日志消息并将它们传递给您正在使用的任何日志记录机制。

    class ConsoleTracer : IServiceClientTracingInterceptor
    {
        public void ReceiveResponse(string invocationId, HttpResponseMessage response) { }
    }
    

    在创建Microsoft.Azure.Management.Fluent.Azure 对象之前,通过调用ServiceClientTracing.AddTracingInterceptor() 初始化您在上面创建的IServiceClientTracingInterceptor 并将ServiceClientTracing.IsEnabled 设置为true。创建 Azure 对象时,请包含 .WithDelegatingHandler().WithLogLevel() 方法以将客户端连接到 AutoRest 的服务客户端跟踪。

    ServiceClientTracing.AddTracingInterceptor(new ConsoleTracer());
    ServiceClientTracing.IsEnabled = true;
    
    var azure = Azure
        .Configure()
        .WithDelegatingHandler(new HttpLoggingDelegatingHandler())
        .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
        .Authenticate(credentials)
        .WithDefaultSubscription();
    

    更多详情可以参考这个article

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-25
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多