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.

  1. In Visual Studio, open the context menu of the ExternalLogging project and click Add» Class.

  2. 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

  1. In Visual Studio, open the context menu of the ExternalLoggingproject and click Add» Class.
  2. Name the class file RaygunTraceListenerClient.csand click Add.
  3. Make the RaygunTraceListenerClientclass implement the ITraceListenerClient interface.
  4. Define the constructor, methods and fields.
    In this part of the code, the GetRaygunAssemblyFromAppDomainmethod checks, if the current application domain contains the assembly required to send errors to the Raygun.io dashboard. 
    In the RaygunTraceListenerClientconstructor, you create an instance of the RaygunClientand configure it to prevent any sensitive information from being sent to the Raygun.io dashboard.
  5. Implement the ITraceListenerClient methods.
    In the LogMessagemethod you get the exception using SystemManager.CurrentHttpContext.Error or in case the value is null, you create a new exception and pass the message. Finally, you use the Raygunclient to send the exception to the Raygun.io dashboard.

GITHUB EXAMPLE: For more information, see RaygunTraceListenerClient.cs file in the downloaded sample.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.