I am trying to put trace or exception data to the Application Insights. I am trying the following code:
TelemetryClient tc = new TelemetryClient();
tc.InstrumentationKey = "xxxxxx-xxxxxxx-xxxxxxxx-xxxxxxx";
tc.TrackTrace(new TraceTelemetry("Console trace critical", SeverityLevel.Critical));
tc.TrackException(new ApplicationException("Test for AI"));
tc.Flush();
But it does not work, I can not find these traces or exceptions on the Application Insights dashboard, search or metric explorer.
I would try adding a 5 seconds sleep before existing the process (after the flush) - IIRC flush only flushes the local buffer, and does not force send the telemetry to Application Insights