I am using this code to send events to application insights in a console application

        TelemetryConfiguration.Active.InstrumentationKey ="XXXXXXXXX";

        TelemetryClient telemetryClient = new TelemetryClient(); 

        for (int i = 0; i < 100; i++)

            telemetryClient.TrackEvent("Hello World!");

            telemetryClient.TrackException(new OutOfMemoryException());


Now the problem i am having is that it is not seeming to log all my events , sometimes the visual studio toolbar says 44 , sometimes it is 68 and never 100 .

The type of information i am going to send is important cause i will be monitoring several console applications from this service .

Is there any way to have application insights send every thing to azure and not skip events ? I think i am giving it enough time to send every thing before exiting .

  • Hello, can you please provide the full code(remove something confidential)? – Ivan Yang Apr 16 at 1:32
  • full code is there now , no idea how those 2 lines would make any difference . – Dotnetsqlcoder Apr 16 at 22:19

Without full code, its hard to say the configuration used.Couple of things to look for:

  1. Have you enabled sampling? If you really want accurate count of events, then disable sampling (https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling)
  2. Have you configured channel explicitly? If not, the default will be InMemoryChannel, which does not do any retries for transient issues. Its best to use ServerTelemetryChannel, to protect data loss in the even of network issue or application insights backend transient issues.
var config = new TelemetryConfiguration(); // or active or create default...
var channel = new ServerTelemetryChannel();

// create client from the config.
TelemetryClient tc= new TelemetryClient(config);

  • full code is there , there was nothing missing honestly except initialization which is why i did not include that at the first place . – Dotnetsqlcoder Apr 16 at 22:20
  • got it - so you are not enabling sampling, so it's not an issue. But you need to do Server channel since you care about reliability of events. – cijothomas Apr 16 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.