Monitoring usage and performance in Windows Desktop apps

Azure Application Insights and HockeyApp let you monitor your deployed application for usage and performance.


We recommend HockeyApp to distribute and monitor desktop and device apps. With HockeyApp, you can manage distribution, live testing, and user feedback, as well as monitor usage and crash reports. You can also export and query your telemetry with Analytics.

Although telemetry can be sent to Application Insights from a desktop application, this is chiefly useful for debugging and experimental purposes.

To send telemetry to Application Insights from a Windows application

  1. In the Azure portal, create an Application Insights resource. For application type, choose ASP.NET app.
  2. Take a copy of the Instrumentation Key. Find the key in the Essentials drop-down of the new resource you just created.
  3. In Visual Studio, edit the NuGet packages of your app project, and add Microsoft.ApplicationInsights.WindowsServer. (Or choose Microsoft.ApplicationInsights if you just want the bare API, without the standard telemetry collection modules.)
  4. Set the instrumentation key either in your code:

    TelemetryConfiguration.Active.InstrumentationKey = " your key ";

    or in ApplicationInsights.config (if you installed one of the standard telemetry packages):

    <InstrumentationKey>your key</InstrumentationKey>

    If you use ApplicationInsights.config, make sure its properties in Solution Explorer are set to Build Action = Content, Copy to Output Directory = Copy.

  5. Use the API to send telemetry.
  6. Run your app, and see the telemetry in the resource you created in the Azure Portal.

Example code

    public partial class Form1 : Form
        private TelemetryClient tc = new TelemetryClient();
        private void Form1_Load(object sender, EventArgs e)
            // Alternative to setting ikey in config file:
            tc.InstrumentationKey = "key copied from portal";

            // Set session data:
            tc.Context.User.Id = Environment.UserName;
            tc.Context.Session.Id = Guid.NewGuid().ToString();
            tc.Context.Device.OperatingSystem = Environment.OSVersion.ToString();

            // Log a page view:

        protected override void OnClosing(CancelEventArgs e)
            stop = true;
            if (tc != null)
                tc.Flush(); // only for desktop apps

                // Allow time for flushing:

Next steps