Application Insights for WPF Application

Avanti Ajay picture Avanti Ajay · Oct 22, 2014 · Viewed 11.7k times · Source

There is a WPF application written in Visual Studio. Can I add Application Insights to this WPF app? I would like to know how many times a button/tile is clicked. Since there are multiple installations of the same application, I would like to know which button was clicked how many times from which user/installation. Can this be done with Application Insights?

Thanks Avanti

Answer

vladjoanovic picture vladjoanovic · Oct 29, 2014

While not listed as a supported app type this means there isn't default telemetry data collected/sent to application insights nor is there support for adding AI/creating an application insights resource. That being said it is possible to add to your WPF with a few manual steps so that you can track the specific scenarios you mention (like a button/tile click).

-From Visual studio add the "Application Insights API" NuGet to the project (.11 is the latest today).

This will add the Application Insights API reference and create an application insights configuration file to your project.

The applicationinsights.config file needs to be updated with your instrumentation key as follows:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">
    <TelemetryChannel>
        <DeveloperMode>false</DeveloperMode>
    </TelemetryChannel>
    <TelemetryModules>
        <Add Type="Microsoft.ApplicationInsights.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights"/>
    </TelemetryModules>
    <InstrumentationKey>**your-instrumentation-key-guid**</InstrumentationKey>
</ApplicationInsights>

To create an application insights instrumentation key login to your azure subscription. https://portal.azure.com Click + to create an Application Insights resource. Then choose the properties tile on the application insights blade and copy the Instrumentation key and add it to your applicationinsights.config file. Now in your WPF app you can use the Application Insights sdk as described here: http://blogs.msdn.com/b/visualstudioalm/archive/2014/10/21/application-insights-sdk-0-11-0-prerelease.aspx

your events will be visible in the diagnostic search blade which can be selected on the application insights blade.

Note: telemetry is batched locally for 1 min before being sent to the service unless > 500 telemetry events are queued at which point they are sent.