How to prevent the loss of telemetry events using the Insight Persistence Channel?

I have included the presentation of Microsoft applications in my Windows Forms application. In the Application Statistics document , in applications, services, and Windows desktop roles that use the default channel in memory after the application falls asleep for one second before exiting.

 tc.Flush(); // only for desktop apps

 // Allow time for flushing:
 System.Threading.Thread.Sleep(1000);

The document states:

Note that Flush () is synchronous for the persistence channel, but asynchronous for the other channels.

As this example uses the in-memory channel, I can subtract that the flushing in the sample code is asynchronous, hence sleep.

In my code, I use a persistence channel. Just before exiting my program, I raise the Application Closing event:

static void Main(string[] args)
{
    try { /* application code */ }
    finally
    {
        Telemetry.Instance.TrackEvent("Application Shutdown");
        Telemetry.Instance.Flush();
        System.Threading.Thread.Sleep(1000); // allow time for flushing
    }
}

, Flush , . , Azure, , " " . Flush, .

, , , %LOCALAPPDATA%\Microsoft\ApplicationInsights.

:

  • Persistence Channel Flush , , Azure?
+4
1

, Flush() (% LOCALAPPDATA% ), . , , , , . , .

+4

Source: https://habr.com/ru/post/1612453/


All Articles