public virtual Response <LogsBatchQueryResult> Submit(CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsBatchQuery)}.{nameof(Submit)}"); scope.Start(); try { var response = _restClient.Batch(_batch, cancellationToken); 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 queries to send.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param> /// <returns>The <see cref="LogsBatchQueryResults"/> containing the query identifier that has to be passed into <see cref="LogsBatchQueryResults.GetResult"/> to get the result.</returns> public virtual Response <LogsBatchQueryResults> QueryBatch(LogsBatchQuery batch, CancellationToken cancellationToken = default) { Argument.AssertNotNull(batch, nameof(batch)); using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(LogsQueryClient)}.{nameof(QueryBatch)}"); scope.Start(); try { var response = _queryClient.Batch(new BatchRequest(batch.Requests), cancellationToken); return(response); } catch (Exception e) { scope.Failed(e); throw; } }