Search code examples
.netazureazure-application-insights

Application Insights from last Debug session


I'm encapsulating TelemetryClient functionality to a framework component for both client and server to use. In the process, trimming dependencies and replacing default behavior with my own.

My problem, however, is although telemetry shows up in debug output, it's not shown in the Application Insights Search window.

AISearch

Note, the telemetry is picked up in Azure Portal.

How can I get data from debug session telemetry, without the full blown Web App to Add Application Insights Telemetry... workflow?

Steps to reproduce:

  • Create Azure resource, replace InstrumentationKey = "###YourKey###" in snippet below
  • Create .NET Framework ConsoleApp
  • Add Microsoft.ApplicationInsights nuget package

Program.cs

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Track.AddEvent("Debugging");
            System.Console.WriteLine("Search Insights");
            System.Console.ReadLine();
        }
    }

    public static class Track
    {
        private static readonly TelemetryClient TelemetryClient;

        static Track()
        {
            TelemetryConfiguration config = TelemetryConfiguration.CreateDefault();
            config.InstrumentationKey = "###YourKey###";
            TelemetryClient = new TelemetryClient(config);
        }

        public static void AddEvent(string eventName)
        {
            TelemetryClient.TrackEvent(eventName);
        }
    }
}

Taking data from Azure Resource.

AzRes


Solution

  • Don't know what caused it, but you can get around by manually adding ApplicationInsights.config.

    Workflow:

    • Right click project: Add new item...
    • Choose: Application Configuration File
    • Name: ApplicationInsights.config

    Running the solution again made the event count appear next to the light bulb.

    • Go to Application Insights Search window
    • Check All
    • Update

    Data from Debug session telemetry shown accordingly.

    Funny thing, if you now remove the config file, the events will still show up in the Application Insights Search window, although the count next to the light bulb disappears again.