首页 文章

C#Application Insight失败:TrackEvent不发送到Azure Application Insight

提问于
浏览
0

我是Azure Application Insight的新手,并尝试通过我的本地计算机发送TrackEvent . 但Azure Application Insight似乎没有收到任何东西 .

这是我的要求 . 规格 . 安装了应用程序洞察sdk nuget的示例asp.net框架控制台代码是通过Telemetry客户端和Instrumental Id配置来设置的 . 控制台运行后,Azure应用程序洞察应该按预期显示历史记录 . 但它没有显示任何东西 . 我错过了什么吗?

我简单的控制台代码

Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = "c453fec7-ea68-4c06-83e4-2938eef1f124";
        TelemetryClient telemetry = new TelemetryClient();
        telemetry.Context.User.Id = "Test User Id.";
        telemetry.Context.User.Id = "Test Device Id.";
        telemetry.TrackEvent("Test TrackEvent");

InstrumentationKey是正确的 . Telemetry.TractEvent方法不会暴露异常 . Azure Application Insight Search(用于自定义事件)不显示历史记录 .

谢谢 .

1 回答

  • 2

    原因可能是由于以下原因之一:

    • 对于.net控制台应用程序,在门户中创建Application Insights时,应为应用程序类型选择"General" . 请参考下面的截图 .
      enter image description here

    2.在您的控制台代码中,您应该添加Flush()和sleep()方法 .

    static void Main(string[] args)
            {
                TelemetryConfiguration.Active.InstrumentationKey = "your key";
                var telemetryClient = new TelemetryClient();
                telemetryClient.Context.User.Id = "uid1";
                telemetryClient.Context.Device.Id = "did1";
                telemetryClient.TrackEvent("AtestEvent7");
                telemetryClient.Flush();
    
                System.Threading.Thread.Sleep(5000);
            }
    

    然后等一会儿,我可以在门户网站上看到自定义事件:
    enter image description here

    顺便说一句,我注意到你在代码中定义了两次 telemetry.Context.User.Id ,也许是一个错字 .

相关问题