Application Insights for WPF Application

前端 未结 3 729
天命终不由人
天命终不由人 2020-12-13 01:17

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 ther

3条回答
  •  无人及你
    2020-12-13 01:45

    Application Insights (AI) for desktop applications is being deprecated in favor of HockeyApp. It's not overly mature yet, but it works (events essentially reach the same place AI events go).

    For example, here's how it looks in RoslynPad (a WPF C# Editor):

    using Microsoft.HockeyApp;
    
    
    //In your initialization method:
    var hockeyClient = (HockeyClient)HockeyClient.Current;
    
    hockeyClient.Configure(HockeyAppId)
        .RegisterCustomDispatcherUnhandledExceptionLogic(OnUnhandledDispatcherException)
        .UnregisterDefaultUnobservedTaskExceptionHandler();
    
    var platformHelper = (HockeyPlatformHelperWPF)hockeyClient.PlatformHelper;
    platformHelper.AppVersion = _currentVersion.ToString();
    
    hockeyClient.TrackEvent("App Start");
    
    //sometime later:
    hockeyClient.TrackEvent("Something happened");
    

    EDIT Looks like the following NuGet package is required in order for this to work properly: https://www.nuget.org/packages/HockeySDK.WPF.TelemetryWorkaround (see https://github.com/bitstadium/HockeySDK-Windows/pull/88).

提交回复
热议问题