How to see my C# trace statement with the "az monitor" command?

Siegfried Heintze 1,506 Reputation points

I have followed this example of a console mode C# program that has a trace statement and I can see my trace statement in the portal when viewing my application insights azure object and selecting logs...

I've been trying and failing to use the az monitor command. Here is my attempt:

az monitor app-insights query  --app c7b4cxxx-xxxx-xxxx-xxxx-cc9d59bd1138  -g rg_csharp_script_demo --analytics-query 'trace'  

(1) I'm not sure what to put for the --app! Can someone please guide me on using this command line interface so I can see my trace statement?

(2) How would the command change if I wanted to see my trace statements in my web app or azure function?

(3) What about trace statements in browser resident source code? Is that an option? How would I do that?

(4) Now the comments for that sample C# console mode program say "// Http dependency is automatically tracked!"... How would I see this with the "az monitor" command?

(5) How would I see this http dependency in the portal?



Tue Nov 28 Update:

This worked from powershell (but not bash) when using the name of the application insighs instead of the appid.

az monitor app-insights query --apps javascriptbindingtest --analytics-query 'traces' --resource-group rg_csharp_script_demo --offset 3d  

So this is good: the main problem is resolved. However, I'm curious why my other attempts did not work using the appid and using the cloud shell:

I carefully followed your directions to fetch the appid from the App Insights on the portal and copy and paste the resource group

az monitor app-insights query --apps c7b4c42d-xxxx-xxxx-xxxx-cc9d59bd1138 --analytics-query 'traces | summarize count() by bin(timestamp, 1h)' --resource-group rg_csharp_script_demo  
ERROR: (ResourceNotFound) The Resource 'Microsoft.Insights/components/c7b4c42d-xxxx-xxxx-xxxx-cc9d59bd1138' under resource group 'rg_csharp_script_demo' was not found. For more details please go to  
Code: ResourceNotFound  
Message: The Resource 'Microsoft.Insights/components/c7b4c42d-xxxx-xxxx-xxxx-cc9d59bd1138' under resource group 'rg_csharp_script_demo' was not found. For more details please go to  

Then I tried it on a cloud prompt:


So why is it not seeing my resource group? This command works from my dev machine so clearly the resource group does exist and I can see it:

Get-AzResource -ResourceGroupName rg_csharp_script_demo | ft  
Name                                        ResourceGroupName     ResourceType                                       Lo  
----                                        -----------------     ------------                                       --  
ASP-rgcsharpscriptdemo-bcd6                 rg_csharp_script_demo Microsoft.Web/serverFarms                          w.  
func-csharp-script-demo                     rg_csharp_script_demo microsoft.insights/components                      w.  
rgcsharpscriptdemoa4c3                      rg_csharp_script_demo Microsoft.Storage/storageAccounts                  w.  
func-csharp-script-demo                     rg_csharp_script_demo Microsoft.Web/sites                                w.  
Failure Anomalies - func-csharp-script-demo rg_csharp_script_demo microsoft.alertsmanagement/smartDetectorAlertRules g.  
stgjavascripttest                           rg_csharp_script_demo Microsoft.Storage/storageAccounts                  w.  
ASP-rgcsharpscriptdemo-beae                 rg_csharp_script_demo Microsoft.Web/serverFarms                          w.  
javascriptbindingtest                       rg_csharp_script_demo microsoft.insights/components                      w.  
javascriptbindingtest                       rg_csharp_script_demo Microsoft.Web/sites                                w.  
Failure Anomalies - javascriptbindingtest   rg_csharp_script_demo microsoft.alertsmanagement/smartDetectorAlertRules g.  
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,073 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 10,546 Reputation points

    @Siegfried Heintze Thanks for reaching out. I understand that you are trying to query the App insights logs from Azure CLI.

    • app property within az monitor command is a GUID, app name, or fully qualified Azure resource name of Application Insights component. The application GUID may be acquired from the API Access menu item on any Application Insights resource in the Azure portal. If using an application name, please specify resource group.


    • Within az monitor command, you have analytics query property where you can pass kusto queries. Below is sample example for trace: az monitor app-insights query --app e292531c-eb03-4079-9bb0-fe6b56b99f8b --analytics-query 'traces | summarize count() by bin(timestamp, 1h)'

    To further understand az monitor app-insights query command, refer this document.

    • All the logs which are inserted into application insights follows below standardized telemetry model. Each of which can be accessed using kusto queries (KQL). To further understand the telemetry model and how to use formulate kusto queries refer this and this documents.
    0 comments No comments