Create the client class
After you prepare the project, you implement the client class. The client class is used to wrap the logic that performs error logging to an external application. In this tutorial, the external application that is used for error logging is the Raygun.io dashboard.
-
In Visual Studio, open the context menu of the ExternalLogging project and click Add» Class.
-
Name the class file
ITraceListenerClient.csand click Add.GITHUB EXAMPLE: For more information, see ITraceListenerClient.cs file of the downloaded sample project.
In this code above, you define an interface for the custom trace listener clients. By using this interface, you can easily substitute the client, which you create in a later step of this tutorial, and implement a different logic for logging errors.
Implement the ITraceListenerClient interface
- In Visual Studio, open the context menu of the ExternalLoggingproject and click Add» Class.
- Name the class file
RaygunTraceListenerClient.csand click Add. - Make the
RaygunTraceListenerClientclass implement theITraceListenerClientinterface. - Define the constructor, methods and fields.
In this part of the code, theGetRaygunAssemblyFromAppDomainmethod checks, if the current application domain contains the assembly required to send errors to the Raygun.io dashboard.
In theRaygunTraceListenerClientconstructor, you create an instance of theRaygunClientand configure it to prevent any sensitive information from being sent to the Raygun.io dashboard. - Implement the
ITraceListenerClientmethods.
In theLogMessagemethod you get the exception usingSystemManager.CurrentHttpContext.Erroror in case the value isnull, you create a new exception and pass the message. Finally, you use theRaygunclient to send the exception to the Raygun.io dashboard.
GITHUB EXAMPLE: For more information, see RaygunTraceListenerClient.cs file in the downloaded sample.