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.cs and 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 ExternalLogging project and click Add » Class.
  2. Name the class file RaygunTraceListenerClient.cs and click Add.
  3. Make the RaygunTraceListenerClient class implement the ITraceListenerClient interface.
  4. Define the constructor, methods and fields.
    In this part of the code, the GetRaygunAssemblyFromAppDomain method checks, if the current application domain contains the assembly required to send errors to the Raygun.io dashboard. 
    In the RaygunTraceListenerClient constructor, you create an instance of the RaygunClient and configure it to prevent any sensitive information from being sent to the Raygun.io dashboard.
  5. Implement the ITraceListenerClient methods.
    In the LogMessage method 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 Raygun client 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?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?