Search code examples
c#.netwcftrace

Remote Service Trace Listener while logging System.ServiceModel


In our project we need to transmit the client side logging to a server. Server-side, we created a WCF service that can receive the logging lines and dump them into a flat file/xml file/database (not important). Client-side, we created a RemoteTraceListener (with attributes to configure the endpoint, etc) calling that logging service. We use the standard .Net tracing with trace sources (TraceData, TraceEvent) to create the logging.

Now, this all goes well, unless we hook up the RemoteTraceListener to the "System.ServiceModel" trace source at the client to investigate other service calls. This obviously goes very wrong.

  • System.ServiceModel trace source message of MalfunctioningServiceX is logged to RemoteTraceListener.
  • RemoteTraceListener makes Wcf connection to send out the logging line to logging service
  • System.ServiceModel trace source message of RemoteTraceListener is logged to RemoteTraceListener.
  • ...

And after that, the messages just keep flooding. Ideas on solving this recursion, please?


Solution

  • After thorough searching, the possible solutions split itself in three categories:

    • Don't use WCF to transmit the logging (use a logging framework using another method of communication)
    • First log locally and stop logging when transmitting the log file or use another method to transmit the log file.
    • Separate the transmission from the application, using another executable or another AppDomain

    We chose to follow the last method. We have rewritten our TraceListener to write internally to a queue. Internally a second AppDomain is started, dequeuing and transmitting the logging to the server. This can be written in half a day.