Search code examples
azureazure-application-insightsazure-monitoring

Cannot find my azure endpoint for LogQueryClient


I'm trying to access logs from my application insights from code via LogsQueryClient. In documentation I see that I would need endpoint to my azure monitor(which is logical) but I'm unable to find it in azure and when googling I had no luck finding what I need or at least didn't find something that would look to me like answer to my problem. This is constructor I believe I should use from documentation.

Any help would be kindly appreciated thanks.


Solution

  • You only need the workspaceId of your Log Analytics Workspace:

    enter image description here

    Then query like this:

    logsQueryClient = new LogsQueryClient(new DefaultAzureCredential());
    var response = await logsQueryClient.QueryWorkspaceAsync("2c6892c2-6c05-49f8-a88c-********", "apprequests | take 10", new QueryTimeRange(TimeSpan.FromHours(1)));