0

Does anyone have Application Insights working for a project that uses .NET 4.8 and Startup.cs, Configure Services. It does not have global.asax. We are using .NET 4.8 and ASpNetCore 2.1.7 dependency for the project. I tried doing the SDK local but do not see API requests and Telemetry on Visual Studio. I am using Postman to send a request to the API.

Where should I add the instrumentation key? The project has an App.Config, it does not have Appsettings.json or ApplicationInsights.config.

enter image description here

enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9
user575219
  • 2,346
  • 15
  • 54
  • 105
  • ...you're using `Microsoft.ApplicationInsights.AspNetCore` in a **non-ASP.NET Core** project. That's your problem. – Dai Aug 21 '23 at 21:51
  • Does this help https://stackoverflow.com/questions/73345475/application-insights-configuration-in-asp-net-4-8-web-application? – Qiang Fu Aug 22 '23 at 07:54
  • @Dai not quite - ASP.NET Core 2 did run on .NET Framework. So the project *is* ASP.NET Core but *not* .NET Core. And, is no longer supported. Even if there is a `Microsoft.ApplicationInsights.AspNetCore` version for ASP.NET Core 2, it may be so old it no longer supports the current App Insights API – Panagiotis Kanavos Aug 23 '23 at 08:18
  • ASP.NET Core 2 in general, not just over .NET Framework, reached End Of Life several years ago. The oldest supported version is ASP.NET Core 6, over .NET 6. While the [packaged does target .NET Standard 2](https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.22.0-beta3#supportedframeworks-body-tab), modern Visual Studio versions won't include wizards for such an old unsupported stack. That's what `unsupported` means. – Panagiotis Kanavos Aug 23 '23 at 08:22
  • You can configure App Insights manually after installing the package. You may be able to get the wizards if the Visual Studio Installer still contains an ASP.NET Core 2 target. Shouldn't you be looking at migrating though? ASP.NET Core 2 doesn't even get security updates any more. – Panagiotis Kanavos Aug 23 '23 at 08:25
  • Why are you targeting a dead runtime in a *new* project anyway? Is there a real reason? Perhaps you can *fix* that reason so you can use a supported runtime? If you fear there won't be a .NET Core runtime in production, you can create a self-contained deployment that *includes* the desired runtime. – Panagiotis Kanavos Aug 23 '23 at 09:15

1 Answers1

-1

From your Screenshots it is clear that you are using Console Application and App.config.

As mentioned in the MSDoc, for a Console application to Log traces to Application Insights, you need to Install Microsoft.ApplicationInsights.WorkerService NuGet Package.

OR

The project has an App.Config, it does not have Appsettings.json or ApplicationInsights.config

  • You can use either App.config or ApplicationInsights.config file to add Instrumentation Key.

If you don't want to add manually, you can add from the Connected Services (ApplicationInsights.config will be generated, you can use this to add Instrumentation Key)

enter image description here

enter image description here

Packages related to Application Insights will be added. You can check the same in .csproj or in Assemblies.

enter image description here

Add the Instrumentation Key before </ApplicationInsights> in the ApplicationInsights.config file.

enter image description here

<InstrumentationKey>**********</InstrumentationKey>

Update

The above configuration of Application Insights is for the .NET Console Application.

In your previous question you mentioned that

On top, it has an added an ASP.NET Core Configure Services Startup.cs.

Thanks @PanagiotisKanavos for the comments.

As mentioned by Panagiotis, Migrating from Framework Application to Core requires lot of changes or configurations to be done.

The Packages which you have added for Application Insights are for Core Application.

If you want to configure application Insights in .NET Core, then you need to have appsettings.json file.

Harshitha
  • 3,784
  • 2
  • 4
  • 9
  • The answer is almost wrong. The question shows ASP.NET Core 2 which *did* run on .NET Framework. Multi-targeting won't help if there's no Microsoft.ApplicationInsights.AspNetCore version that targets ASP.NET Core 2. Migrating to a supported ASP.NET Core version will require extensive changes and once that's done, there won't be any point to multi-targeting – Panagiotis Kanavos Aug 23 '23 at 08:17
  • @PanagiotisKanavos - I have missed the Core Version, mentioned the AppInsights Configuration for Framework.Will check and update the answer accordingly. – Harshitha Aug 23 '23 at 08:52
  • 1
    It seems the OP's question is why there's no VS wizard for this. It's quite possible that VS no longer supports ASP.NET Core 2 at all and the OP will have to manually add App Insights support, making by hand the code and script changes required, eg add interceptors and filters, add the script call in the layout page etc. The instructions for VS Code or Rider would be more helpful in this case – Panagiotis Kanavos Aug 23 '23 at 09:19
  • If he want to log configuration for Core, he need to have `appsettings.json`. And you have already mentioned, it requires lot of changes to be done to migrate from 2.0 to later versions (6.0 or 7.0). – Harshitha Aug 23 '23 at 09:26
  • @user575219 - Refer this [SO Thread](https://stackoverflow.com/a/73566848/19648279) which explains the AppInsights Configuration for a Core Application.If you want to continue with the Core 2.0, manually add the required packages. – Harshitha Aug 23 '23 at 09:47