gpt4 book ai didi

c# - 如何使用 Application Insight 的持久性 channel 防止丢失遥测 pageView?

转载 作者:太空宇宙 更新时间:2023-11-03 14:46:55 25 4
gpt4 key购买 nike

当互联网连接可用时,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();
}

更新

要跟踪页面浏览量,您可以使用 TelemetryClientTrackPageView 之一重载,例如:

telemetryClient.TrackPageView("MyPageName");

希望对你有帮助!

关于c# - 如何使用 Application Insight 的持久性 channel 防止丢失遥测 pageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53826410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com