o retrieve all events with the name "AssetPlaybackData" from Application Insights using C#, you can indeed use the LogsQueryClient
class provided by the Azure.Monitory.Query
package.
Here's some sample code that shows how to use the LogsQueryClient
to retrieve all events with the name "AssetPlaybackData" from a given Application Insights resource:
using Azure.Identity;
using Azure.Monitor.Query;
using Azure.Monitor.Query.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public class AppInsightsQuery
{
public async Task<List<LogsQueryResult>> GetAssetPlaybackDataEventsAsync(string workspaceId, string appId, string clientSecret)
{
var tenantId = "<your-tenant-id>";
var credential = new ClientSecretCredential(tenantId, appId, clientSecret);
var client = new LogsQueryClient(credential);
// The query to retrieve events with the name "AssetPlaybackData"
var query = $"AppEvents | where name == 'AssetPlaybackData'";
// The workspace ID for your Application Insights resource
var workspace = $"/subscriptions/<your-subscription-id>/resourcegroups/<your-resource-group>/providers/microsoft.operationalinsights/workspaces/{workspaceId}";
var result = await client.QueryAsync(workspace, query);
return result.ToList();
}
}
To use this code, you'll need to provide your Azure AD tenant ID, your Application ID, your client secret, your subscription ID, and your resource group name. You'll also need to specify the workspace ID for your Application Insights resource.
Once you have this code, you can call the GetAssetPlaybackDataEventsAsync
method to retrieve all events with the name "AssetPlaybackData" from your Application Insights resource. The method returns a list of LogsQueryResult
objects, which contain the event data.