你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

LogsQueryClient.QueryBatch(LogsBatchQuery, CancellationToken) 方法

定义

提交批处理查询。 LogsBatchQuery使用 编写批处理查询。

string workspaceId = "<workspace_id>";

var client = new LogsQueryClient(new DefaultAzureCredential());

// Query TOP 10 resource groups by event count
// And total event count
var batch = new LogsBatchQuery();

string countQueryId = batch.AddWorkspaceQuery(
    workspaceId,
    "AzureActivity | count",
    new QueryTimeRange(TimeSpan.FromDays(1)));
string topQueryId = batch.AddWorkspaceQuery(
    workspaceId,
    "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count",
    new QueryTimeRange(TimeSpan.FromDays(1)));

Response<LogsBatchQueryResultCollection> response = await client.QueryBatchAsync(batch);

var count = response.Value.GetResult<int>(countQueryId).Single();
var topEntries = response.Value.GetResult<MyLogEntryModel>(topQueryId);

Console.WriteLine($"AzureActivity has total {count} events");
foreach (var logEntryModel in topEntries)
{
    Console.WriteLine($"{logEntryModel.ResourceGroup} had {logEntryModel.Count} events");
}
public virtual Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResultCollection> QueryBatch (Azure.Monitor.Query.LogsBatchQuery batch, System.Threading.CancellationToken cancellationToken = default);
abstract member QueryBatch : Azure.Monitor.Query.LogsBatchQuery * System.Threading.CancellationToken -> Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResultCollection>
override this.QueryBatch : Azure.Monitor.Query.LogsBatchQuery * System.Threading.CancellationToken -> Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResultCollection>
Public Overridable Function QueryBatch (batch As LogsBatchQuery, Optional cancellationToken As CancellationToken = Nothing) As Response(Of LogsBatchQueryResultCollection)

参数

batch
LogsBatchQuery

要发送的查询批。

cancellationToken
CancellationToken

要使用的 CancellationToken

返回

包含 LogsBatchQueryResultCollection 必须传入 GetResult(String) 才能获取结果的查询标识符的 。

适用于