0

I am a total noob with Application Insights, and sadly for a whole day of trying I have been unable to get it working at all. I tried with the following code:

this.telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault());
this.telemetryClient.TrackTrace($"Test", Microsoft.ApplicationInsights.DataContracts.SeverityLevel.Warning);

But when I go to the application insights window and show all telemetry from the current debugging session there is nothing logged. One user said an ApplicationInsights.config file is missing (and that an empty one would do fine for debugging), I created one but it changed nothing.

Then I tried the simplest console app I could find - https://learn.microsoft.com/en-us/azure/azure-monitor/app/console . I don't have an instrumentation key, and from the hundreds of forums I read today, if you leave it blank it should still appear in the debugging telemetry. Alas, still nothing in Application Insights.

How can I get it working? I just want to see a single Trace message in the Visual Studio Application Insights window when queried for "debugging telemetry".

Eduard G
  • 443
  • 5
  • 21

1 Answers1

5

I used to work on this stuff and the way it generally works, the extension tries to figure out if it should watch for debug output, and if it doesn't recognize the project type, we do nothing (to avoid doign work in the debugger when we don't need to). in this case, console apps aren't a "known" supported project type.

IIRC, to get debug output I believe you need to do 2 things, of which you've done 1:

1) add an ApplicationInsights.config file at the root of that project

2) add an application insight resource id to to the csproj:

 <ApplicationInsightsResourceId>/subscriptions/abc</ApplicationInsightsResourceId>

i don't think the resource id even needs to be valid, but if it does even better, because then other things can light up, like exceptions codelens, various links to the portal/etc.

you migth only need to do #2?

i think that if you do the above and restart vs/reload the solution, you should see the debugger integration try to do work when the debugger starts. (it used to!)

John Gardner
  • 24,225
  • 5
  • 58
  • 76
  • Afaik the config file is not used anymore with a .net core project. – Peter Bons Oct 10 '19 at 04:01
  • In a NETCore app, adding an "ApplicationInsights.config" solved it, adding the ApplicationInsightsResourceId did nothing. Anyway, you sir are a God amongst men, thank you. – Eduard G Oct 10 '19 at 08:33
  • yes, the config file isn't used by the project itself, but this "tricks" the tooling into thinking it is a supported project – John Gardner Oct 10 '19 at 17:31
  • 1
    #2 did it for me.. Probably, emphasize more on restarting visual studio. It made me go crazy for a few hours after making this change and trying to make it work without restarting vs. – Bharathi Nov 03 '20 at 02:55