I went through the following tutorial to add AppInsights into a C# project
https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net
Using the manual method. All worked as expected.
I now want to add this same feature into a .Net Framework Class Library.
Following that tutorial I can't carry out steps 5 and 6 because they are explicitly used in an MVC project.
How could I add or what is the equivalent code for steps 5 and 6 from that link to add the same code into a .Net Framework Class Library?
Edit 1
So after implementing the manual method in an MVC app all looks good.
In my Class Library in the constructor i have added similar code as below
private TelemetryClient _telClient;
public class SomeClass(TelemetryClient telClient)
{
_telClient = new TelemetryClient();
}
public void SomeMethod()
{
_telClient.TrackException(new Exception("Hello World");
}
In my MVC app i have the below code
if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
{
//If customError is Off, then AI HTTPModule will report the exception
if (filterContext.HttpContext.IsCustomErrorEnabled)
{
var ai = new TelemetryClient();
ai.TrackException(filterContext.Exception);
SomeClass sc = new SomeClass(ai);
}
}