How to log data to Azure Log Analytics workspace from c# code?

Gerard Tobin 1 Reputation point
2023-01-09T20:09:12.977+00:00

In Log Analytics workspace, I am accessing the union of the AppRequests table and AppExceptions tables

"AppExceptions | join(AppRequests) on OperationId ",
and printing out the "Properties" column (this is a dynamic list) when there is an exception. For example
277598-image.png

However I also get entries such as this where the fields of the "Properties" column are different.

277583-image.png

How do I get the App Service application code to log a custom field and value in "Properties"? The App Service app is a web service. It takes as a parameter something called
"ConversationId" . In the first screen shot I can see an entry for "prop__ConversationId" but not in the second screen shot. I want to capture this "ConversationId" in the logs.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,645 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Udaiappa Ramachandran 726 Reputation points MVP
    2023-01-10T01:53:27.407+00:00

    Log Analytics and Application Insight are part of Azure Monitoring. Log Analytics is a feature that is part of many services. Application Insights resources provide the "Log Analytics" feature. So you can write custom properties to application insights and drill using the log analytics.

    Azure Monitor Overview: https://learn.microsoft.com/en-gb/azure/azure-monitor/overview?WT.mc_id=AZ-MVP-5004665

    To write data to application insight follow the two steps

    1. create a C# class using the following snippets, please make sure replace the highlighted values
      277682-image.png
    2. Configure using the ApplicationInsight.config. To config, open the file and add the type under initializers
      277654-image.png
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.