Create the trace listener class
After you create the client class, you implement the trace listener class. The trace listener derives from the CustomTraceListener class, which exposes methods for writing trace information. To create the trace listener class:
-
In Visual Studio, open the context menu of the ExternalLogging project and click Add » Class
-
Name the class file
RaygunTraceListener.csand click Add. -
Make the
RaygunTraceListenerclass inherit theCustomTraceListenerclass. -
Define the following constructors and the fields.
In this section of the code, you define a parameterless constructor chained to a constructor that accepts an
ITraceListenerClientparameter. Although this implementation of theRaygunTraceListeneruses theRaygunTraceListenerClientclass that you previously created, you can easily create your own client class and pass it as a parameter in the constructor. -
Implement the
CustomTraceListenermethods.
In the code above, you check the type of the trace data that theTraceDatamethod receives and call theWritemethod. TheWritemethod then sends the information provided by the trace data to the client.
GITHUB EXAMPLE: For more information about the content of the file, see the RaygunTraceListener.cs file of the downloaded sample project.