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

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

当互联网连接可用时,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/

相关文章:

azure - Azure Release Pipeline的下载结果

Pod 在线时 Azure CSI Key Vault 提供程序动态更新 secret

c# - 在查询转到 SQL Server 之前是否触发了任何事件?

c# - 打开和修改 Word 文档

c# - 添加 Web 引用时拒绝访问路径

azure - 我可以使用 azure key Vault 通过 jarsigner 对 jar 文件进行签名吗

python - 使用 azure 函数时未找到名为 twilio 的模块

azure-devops - 有没有办法将特定文件排除在 Azure DevOps 上的代码审查义务之外?

azure-devops - 如何为基于 YAML 的管道创建管道变量?

c# - 为什么UserControl文本 block 在设计模式下振动