Ava*_*jay 23 wpf visual-studio azure-application-insights azure-devops
有一个用Visual Studio编写的WPF应用程序.我可以将Application Insights添加到此WPF应用程序中吗?我想知道点击按钮/磁贴的次数.由于同一个应用程序有多个安装,我想知道哪个按钮被点击了多少次用户/安装.可以使用Application Insights完成吗?
谢谢阿凡提
小智 30
虽然未列为受支持的应用类型,但这意味着没有收集/发送到应用程序洞察的默认遥测数据,也不支持添加AI /创建应用程序洞察资源.也就是说,可以通过几个手动步骤添加到WPF,以便您可以跟踪您提到的特定方案(如按钮/磁贴单击).
- 从Visual Studio中将"Application Insights API"NuGet添加到项目中(.11是今天的最新版本).
这将添加Application Insights API参考并为您的项目创建应用程序洞察配置文件.
需要使用检测密钥更新applicationinsights.config文件,如下所示:
<?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>
Run Code Online (Sandbox Code Playgroud)
要创建应用程序洞察检测,请键入登录到您的azure订阅. https://portal.azure.com 单击+以创建Application Insights资源.然后在应用程序见解刀片上选择属性磁贴,并复制Instrumentation键并将其添加到applicationinsights.config文件中.现在,在您的WPF应用程序中,您可以使用此处所述的Application Insights sdk:http://blogs.msdn.com/b/visualstudioalm/archive/2014/10/21/application-insights-sdk-0-11-0- prerelease.aspx
您的事件将显示在诊断搜索刀片中,可以在应用程序洞察刀片上进行选择.
注意:遥测在发送到服务之前在本地批量处理1分钟,除非> 500个遥测事件排队等待它们被发送.
ben*_*ben 12
https://azure.microsoft.com/en-us/documentation/articles/app-insights-windows-desktop/
Microsoft关于如何将Application Insights添加到Windows窗体应用程序的官方链接.从链接:
在Azure中 - portal.azure.com
在您的申请中
TelemetryClient.我在WPF应用程序中使用MvvmCross,在启动时我创建了一个TelemetryClient我在整个应用程序中重复使用的单个.
var telemetryClient = new TelemetryClient();
telemetryClient.InstrumentationKey = "your key here from Azure";
telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();
telemetryClient.Context.User.AccountId = Username;
telemetryClient.Context.Component.Version = Settings.Default.Version;
telemetryClient.TrackEvent("Application Start");
Mvx.RegisterSingleton<TelemetryClient>(telemetryClient);
Run Code Online (Sandbox Code Playgroud)
任何时候'事情发生'我将解决TelemetryClient并记录事件.这与跟踪和记录方面的任何其他Application Insights实现一样.
举个例子 -
//Resolve the telemetry client
readonly TelemetryClient telemetryClient = Mvx.Resolve<TelemetryClient>();
//Record a page View with some extra information
var pageviewTelemetry = new PageViewTelemetry("Observations");
pageviewTelemetry.Properties.Add("Breadcrumb", breadcrumb);
telemetryClient.TrackPageView(pageviewTelemetry);
//Track an event
var eventTelemetry = new EventTelemetry("Observation Saved");
eventTelemetry.Properties.Add("Saved Observation", observation);
telemetryClient.TrackEvent(eventTelemetry);
//Track an exception
try
{
// do work here
}
catch (Exception ex)
{
telemeteryClient.TrackException(ex);
}
Run Code Online (Sandbox Code Playgroud)
Windows桌面应用程序的Application Insights不会自动收集/发送任何内容.作为开发人员,需要在应用程序退出时强制刷新.
private void PowerButton_OnClick(object sender, RoutedEventArgs e)
{
var tc = Mvx.Resolve<TelemetryClient>();
if (null != tc)
{
tc.Flush(); // only for desktop apps
}
Application.Current.Shutdown();
}
Run Code Online (Sandbox Code Playgroud)
或者设置一个RxTimer按计划刷新......我决定每30分钟刷新一次:
var observable = Observable.Interval(new TimeSpan(0, 0, 30, 0));
observable.Subscribe(_ => Application.Current.Dispatcher.Invoke(new Action(() =>
{
var tc = Mvx.Resolve<TelemetryClient>();
if (null != tc)
{
tc.Flush(); // only for desktop apps
Console.WriteLine("Flush TC");
}
})));
Run Code Online (Sandbox Code Playgroud)
仅供参考 - 从Application Insights API NuGet包的0.17.0开始,如果您处于脱机状态,则刷新呼叫不会挂起,但会显示为.在线,呼叫立即完成,离线在呼叫完成前有5秒暂停.
桌面应用程序的Application Insights(AI)正在被弃用,以支持HockeyApp.它还没有过于成熟,但它有效(事件基本上达到AI事件的同一个地方).
例如,这是它在RoslynPad(WPF C#编辑器)中的外观:
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");
Run Code Online (Sandbox Code Playgroud)
编辑看起来需要以下NuGet包才能使其正常工作:https://www.nuget.org/packages/HockeySDK.WPF.TelemetryWorkaround(请参阅https://github.com/bitstadium/HockeySDK-Windows/拉/ 88).
| 归档时间: |
|
| 查看次数: |
10501 次 |
| 最近记录: |