I am using Microsoft Application Insights
for my Web Application. I used the Application Insights TraceListener NuGet package for logging. That worked perfectly.
Now I would like to switch to NLog. I added the Microsoft.ApplicationInsights.NLogTarget
NuGet package and added a new NLog target in my NLog configuration file:
<target name='ai' xsi:type='ApplicationInsights' />
NLog throws an exception:
Target cannot be found: 'ApplicationInsights'
I also tried adding the assembly via extensions like so:
<extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
But it did not work either.
Any suggestions?
By default, when you use the automated experience from the Visual Studio template projects that support Add > Application Insights Telemetry, the ApplicationInsights. config file is created in the project root folder. When it's compiled, it's copied to the bin folder.
Select File | New Project. Select Visual C# | . NET Core | ASP.NET Core Web Application, ensure to mark the checkbox Add Application Insights to Project. Click Ok on the next screen.
Diagnose exceptions using Visual StudioOpen the Application Insights Search telemetry window in Visual Studio. While debugging, select the Application Insights dropdown box. Select an exception report to show its stack trace. To open the relevant code file, select a line reference in the stack trace.
Open your project in Visual Studio. Go to Project > Add Application Insights Telemetry. Choose Azure Application Insights, then select Next. Choose your subscription and Application Insights instance (or create a new instance with Create new), then select Next.
If anyone else stumbles over this:
The correct target type is ApplicationInsightsTarget
not ApplicationInsights
.
This works fine:
<extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
<targets>
<target name='ai' xsi:type='ApplicationInsightsTarget' />
</targets>
No need to add the target by code.
See also: https://github.com/microsoft/ApplicationInsights-dotnet/tree/main/LOGGING#nlog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With