当互联网连接可用时,wpf 应用程序的应用程序洞察工作正常,我能够跟踪 azure 门户中的页面和事件,但我想知道是否可以在没有互联网连接时将遥测数据存储在系统中的某个位置并检索当系统在线时它会跟踪我在没有互联网连接时执行的那些操作。
最佳答案
我建议你看看Application Insights for Desktop Applications ,它提供了将Application Insights与桌面应用程序结合使用的很好的代码示例,以及如何工作/使用持久性 channel 。取自上述链接:
public MainWindow()
{
TelemetryConfiguration config = TelemetryConfiguration.CreateDefault();
config.InstrumentationKey = "954f17ff-47ee-4aa1-a03b-bf0b1a33dbaf";
config.TelemetryChannel = new PersistenceChannel();
config.TelemetryChannel.DeveloperMode = Debugger.IsAttached;
telemetryClient = new TelemetryClient(config);
telemetryClient.Context.User.Id = Environment.UserName;
telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();
InitializeComponent();
}
然后:
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
...
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
ExceptionTelemetry excTelemetry = new ExceptionTelemetry((Exception)e.ExceptionObject);
excTelemetry.SeverityLevel = SeverityLevel.Critical;
excTelemetry.HandledAt = ExceptionHandledAt.Unhandled;
telemetryClient.TrackException(excTelemetry);
telemetryClient.Flush();
}
更新
要跟踪页面浏览量,您可以使用 TelemetryClient 的 TrackPageView 之一重载,例如:
telemetryClient.TrackPageView("MyPageName");
希望对你有帮助!
关于c# - 如何使用 Application Insight 的持久性 channel 防止丢失遥测 pageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53826410/