public virtual async Task <Response <LogsBatchQueryResult> > SubmitAsync(CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsBatchQuery)}.{nameof(Submit)}"); scope.Start(); try { var response = await _restClient.BatchAsync(_batch, cancellationToken).ConfigureAwait(false); response.Value.RowBinder = _rowBinder; return(response); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Submits the batch query. Use the <see cref="LogsBatchQuery"/> to compose a batch query. /// <code snippet="Snippet:BatchQuery" language="csharp"> /// 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"); /// } /// </code> /// </summary> /// <param name="batch">The batch of Kusto queries to send.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>The <see cref="LogsBatchQueryResults"/> that allows retrieving query results.</returns> public virtual async Task <Response <LogsBatchQueryResults> > QueryBatchAsync(LogsBatchQuery batch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(batch, nameof(batch)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(QueryBatch)}"); scope.Start(); try { var response = await _queryClient.BatchAsync(new BatchRequest(batch.Requests), cancellationToken).ConfigureAwait(false); return(response); } catch (Exception e) { scope.Failed(e); throw; } }