Track exceptions via .NET agent API
The .NET agent API helps in keeping track of exceptions handled in .NET and .NET Core applications. To track handled exceptions, it must be called inside the catch block.
The APM Insight .NET agent tracks a few logging providers by default, including log4net, NLog, and Serilog. On the other hand, the APM Insight agent profiler will not know the signature of your application methods if you use your own logging framework. In such cases, you can use .NET agent API to track the exceptions.
Steps:
- Install APM Insight .NET agent or APM Insight .NET Core agent based on your application environment.
- Download or reference the package Site24x7.Agent.Api from the NuGet package manager to your application project.
Note: The API has a class named Site24x7.Agent.Api to track the performance of application code. - Use the method TraceError(Exception exceptionObject) to track any exception in a transaction.
Parameter Name |
Description |
---|---|
exceptionObject |
The exception object that you want to track. |
Example:
The following method illustrates how to track an exception via API.
public int UserLogin()
{
try
{
MyClass myClass = ;
int b = 0;
int invalidResult = a / b;
}
catch (Exception ex)
{
Site24x7.Agent.Api.TraceError(ex);
}
}
To View: