【问题标题】:How to prevent losing telemetry pageView with Application Insight's Persistence Channel?如何使用 Application Insight 的 Persistence Channel 防止丢失遥测 pageView?
【发布时间】:2019-05-18 11:31:39
【问题描述】:

当互联网连接可用时,wpf 应用程序的应用程序洞察力工作正常,我能够在 azure 门户中跟踪页面和事件,但我想知道当它们没有互联网连接时是否可以将遥测数据存储在系统中的某处并检索它在系统在线时跟踪我在没有互联网连接时执行的操作。

【问题讨论】:

  • 你好,你可以看看这个post。这应该是可能的,但可能很困难并且有一些限制。
  • 我能获得在 wpf @IvanYang 中实现持久性通道的 c# 代码
  • 应该可以,但是我对wpf项目不熟悉,可以创建github issue求指导。

标签: c# azure azure-devops azure-application-insights


【解决方案1】:

我建议你看看Application Insights for Desktop Applications,它有很好的代码示例,可以将Application Insights 与桌面应用程序一起使用,以及如何使用/使用Persistence 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");

希望对你有帮助!

【讨论】:

  • 我可以得到它的网页浏览量@Itay Podhajcer
  • 但是持久化通道有一个bug....由于网络适配器的原因,没有收集到数据。 :)
猜你喜欢
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多