LogsQueryClient.QueryBatchAsync(LogsBatchQuery, CancellationToken) Method

Definition

Submits the batch query. Use the LogsBatchQuery to compose a batch query.

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.AddQuery(
    workspaceId,
    "AzureActivity | count",
    new DateTimeRange(TimeSpan.FromDays(1)));
string topQueryId = batch.AddQuery(
    workspaceId,
    "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count",
    new DateTimeRange(TimeSpan.FromDays(1)));

Response<LogsBatchQueryResults> 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 System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResults>> QueryBatchAsync (Azure.Monitor.Query.LogsBatchQuery batch, System.Threading.CancellationToken cancellationToken = default);
abstract member QueryBatchAsync : Azure.Monitor.Query.LogsBatchQuery * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResults>>
override this.QueryBatchAsync : Azure.Monitor.Query.LogsBatchQuery * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Monitor.Query.Models.LogsBatchQueryResults>>
Public Overridable Function QueryBatchAsync (batch As LogsBatchQuery, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of LogsBatchQueryResults))

Parameters

batch
LogsBatchQuery

The batch of queries to send.

cancellationToken
System.Threading.CancellationToken

The System.Threading.CancellationToken to use.

Returns

System.Threading.Tasks.Task<Response<LogsBatchQueryResults>>

The LogsBatchQueryResults that allows retrieving query results.

Applies to