使用流畅的API跟踪异步Azure操作

问题描述 投票:0回答:1

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

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

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

干杯!

azure azure-api-management azure-management-api azure-fluent-api
1个回答
1
投票

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

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

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

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

在创建Microsoft.Azure.Management.Fluent.Azure对象之前,通过调用IServiceClientTracingInterceptor并将ServiceClientTracing.AddTracingInterceptor()设置为true来初始化上面创建的ServiceClientTracing.IsEnabled。创建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

© www.soinside.com 2019 - 2024. All rights reserved.