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.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?