C#应用程序洞察失败:TrackEvent不会发送到Azure应用程序洞察

时间:2018-08-27 08:45:28

标签: azure-application-insights

我对Azure Application Insight完全陌生,并尝试通过本地计算机发送TrackEvent。但是Azure Application Insight似乎什么也没收到。

这是我的必需品。规格 我的示例asp.net框架控制台代码已安装了应用程序见解sdk nuget,并且已配置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搜索(用于自定义事件)不显示历史记录。

谢谢。

1 个答案:

答案 0 :(得分:4)

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

  1. 对于.net控制台应用程序,在门户中创建Application Insights时,应为“应用程序类型”选择“常规”。请参考下面的截图。 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,也许是错字。