C# Application Insight Failure: TrackEvent Does not send to Azure Application Insight

非 Y 不嫁゛ 提交于 2021-01-01 06:49:07

问题


I am completely new to Azure Application Insight and trying to send TrackEvent from via my Local Computer. But Azure Application Insight does not seem to receive anything.

Here is my required. Spec. My sample asp.net framework console code with application insight sdk nuget installed is setup with Telemetry client and Instrumental Id configured. After console runs, Azure application insight should show a history as intended. But itsnot showing anything. Am I missing something?

My simple console Code

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 is correct. Telemetry.TractEvent method does not expose exception. Azure Application Insight Search(for custom event) does not show history.

Thank you.


回答1:


The cause maybe due to one of the following:

  1. For .net console app, when create a Application Insights in portal, you should select "General" for Application Type. Please refer screenshots below.

2.In your console code, you should add Flush() and sleep() method.

        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);
        }

Then wait for a while, I can see the custom event in portal:

BTW, I noticed that you define telemetry.Context.User.Id twice in your code, maybe a typo.



来源:https://stackoverflow.com/questions/52035598/c-sharp-application-insight-failure-trackevent-does-not-send-to-azure-applicati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!