Share via


LogsQueryClient.QueryResource Method

Definition

Overloads

QueryResource(ResourceIdentifier, String, QueryTimeRange, LogsQueryOptions, CancellationToken)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

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

string resourceId = "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/<resource_provider>/<resource>";
string tableName = "<table_name>";
Response<LogsQueryResult> results = await client.QueryResourceAsync(
    new ResourceIdentifier(resourceId),
    $"{tableName} | distinct * | project TimeGenerated",
    new QueryTimeRange(TimeSpan.FromDays(7)));

LogsTable resultTable = results.Value.Table;
foreach (LogsTableRow row in resultTable.Rows)
{
    Console.WriteLine($"{row["OperationName"]} {row["ResourceGroup"]}");
}

foreach (LogsTableColumn columns in resultTable.Columns)
{
    Console.WriteLine("Name: " + columns.Name + " Type: " + columns.Type);
}
QueryResource<T>(ResourceIdentifier, String, QueryTimeRange, LogsQueryOptions, CancellationToken)

Returns all the Azure Monitor logs matching the given query for an Azure resource.

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

string resourceId = "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/<resource_provider>/<resource>";
string tableName = "<table_name>";
Response<LogsQueryResult> results = await client.QueryResourceAsync(
    new ResourceIdentifier(resourceId),
    $"{tableName} | distinct * | project TimeGenerated",
    new QueryTimeRange(TimeSpan.FromDays(7)));

LogsTable resultTable = results.Value.Table;
foreach (LogsTableRow row in resultTable.Rows)
{
    Console.WriteLine($"{row["OperationName"]} {row["ResourceGroup"]}");
}

foreach (LogsTableColumn columns in resultTable.Columns)
{
    Console.WriteLine("Name: " + columns.Name + " Type: " + columns.Type);
}

QueryResource(ResourceIdentifier, String, QueryTimeRange, LogsQueryOptions, CancellationToken)

Source:
LogsQueryClient.cs
Source:
LogsQueryClient.cs

Returns all the Azure Monitor logs matching the given query for an Azure resource.

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

string resourceId = "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/<resource_provider>/<resource>";
string tableName = "<table_name>";
Response<LogsQueryResult> results = await client.QueryResourceAsync(
    new ResourceIdentifier(resourceId),
    $"{tableName} | distinct * | project TimeGenerated",
    new QueryTimeRange(TimeSpan.FromDays(7)));

LogsTable resultTable = results.Value.Table;
foreach (LogsTableRow row in resultTable.Rows)
{
    Console.WriteLine($"{row["OperationName"]} {row["ResourceGroup"]}");
}

foreach (LogsTableColumn columns in resultTable.Columns)
{
    Console.WriteLine("Name: " + columns.Name + " Type: " + columns.Type);
}
public virtual Azure.Response<Azure.Monitor.Query.Models.LogsQueryResult> QueryResource (Azure.Core.ResourceIdentifier resourceId, string query, Azure.Monitor.Query.QueryTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member QueryResource : Azure.Core.ResourceIdentifier * string * Azure.Monitor.Query.QueryTimeRange * Azure.Monitor.Query.LogsQueryOptions * System.Threading.CancellationToken -> Azure.Response<Azure.Monitor.Query.Models.LogsQueryResult>
override this.QueryResource : Azure.Core.ResourceIdentifier * string * Azure.Monitor.Query.QueryTimeRange * Azure.Monitor.Query.LogsQueryOptions * System.Threading.CancellationToken -> Azure.Response<Azure.Monitor.Query.Models.LogsQueryResult>
Public Overridable Function QueryResource (resourceId As ResourceIdentifier, query As String, timeRange As QueryTimeRange, Optional options As LogsQueryOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Response(Of LogsQueryResult)

Parameters

resourceId
ResourceIdentifier

The Azure resource ID where the query should be executed.

query
String

The Kusto query to fetch the logs.

timeRange
QueryTimeRange

The time period for which the logs should be looked up.

options
LogsQueryOptions

The LogsQueryOptions to configure the query.

cancellationToken
CancellationToken

The CancellationToken to use.

Returns

The logs matching the query.

Remarks

When the timeRange argument is All and the query argument contains a time range filter, the underlying service uses the time range specified in query.

Applies to

QueryResource<T>(ResourceIdentifier, String, QueryTimeRange, LogsQueryOptions, CancellationToken)

Source:
LogsQueryClient.cs
Source:
LogsQueryClient.cs

Returns all the Azure Monitor logs matching the given query for an Azure resource.

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

string resourceId = "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/<resource_provider>/<resource>";
string tableName = "<table_name>";
Response<LogsQueryResult> results = await client.QueryResourceAsync(
    new ResourceIdentifier(resourceId),
    $"{tableName} | distinct * | project TimeGenerated",
    new QueryTimeRange(TimeSpan.FromDays(7)));

LogsTable resultTable = results.Value.Table;
foreach (LogsTableRow row in resultTable.Rows)
{
    Console.WriteLine($"{row["OperationName"]} {row["ResourceGroup"]}");
}

foreach (LogsTableColumn columns in resultTable.Columns)
{
    Console.WriteLine("Name: " + columns.Name + " Type: " + columns.Type);
}
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<T>> QueryResource<T> (Azure.Core.ResourceIdentifier resourceId, string query, Azure.Monitor.Query.QueryTimeRange timeRange, Azure.Monitor.Query.LogsQueryOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member QueryResource : Azure.Core.ResourceIdentifier * string * Azure.Monitor.Query.QueryTimeRange * Azure.Monitor.Query.LogsQueryOptions * System.Threading.CancellationToken -> Azure.Response<System.Collections.Generic.IReadOnlyList<'T>>
override this.QueryResource : Azure.Core.ResourceIdentifier * string * Azure.Monitor.Query.QueryTimeRange * Azure.Monitor.Query.LogsQueryOptions * System.Threading.CancellationToken -> Azure.Response<System.Collections.Generic.IReadOnlyList<'T>>
Public Overridable Function QueryResource(Of T) (resourceId As ResourceIdentifier, query As String, timeRange As QueryTimeRange, Optional options As LogsQueryOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Response(Of IReadOnlyList(Of T))

Type Parameters

T

Parameters

resourceId
ResourceIdentifier

The Azure resource ID where the query should be executed.

query
String

The Kusto query to fetch the logs.

timeRange
QueryTimeRange

The time period for which the logs should be looked up.

options
LogsQueryOptions

The LogsQueryOptions to configure the query.

cancellationToken
CancellationToken

The CancellationToken to use.

Returns

The logs matching the query.

Applies to