Share via


LogsBatchQuery.AddWorkspaceQuery Method

Definition

Adds the specified query to the batch. Results can be retrieved after the query is submitted via the QueryBatchAsync(LogsBatchQuery, CancellationToken) call.

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);
public virtual string AddWorkspaceQuery (string workspaceId, string query, Azure.Monitor.Query.QueryTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = default);
abstract member AddWorkspaceQuery : string * string * Azure.Monitor.Query.QueryTimeRange * Azure.Monitor.Query.LogsQueryOptions -> string
override this.AddWorkspaceQuery : string * string * Azure.Monitor.Query.QueryTimeRange * Azure.Monitor.Query.LogsQueryOptions -> string
Public Overridable Function AddWorkspaceQuery (workspaceId As String, query As String, timeRange As QueryTimeRange, Optional options As LogsQueryOptions = Nothing) As String

Parameters

workspaceId
String

The workspace to include in the query.

query
String

The query text to execute.

timeRange
QueryTimeRange

The timespan over which to query data.

options
LogsQueryOptions

The LogsQueryOptions to configure the query.

Returns

The query identifier that has to be passed into GetResult(String) to get the result.

Applies to