Remote trace listener

Code first, ask questions later

// servicecontract
public interface ITraceWritable
   void Write(string msg);
// proxy
public partial class RemoteTraceClient : ClientBase<ITraceWritable>, ITraceWritable
   public RemoteTraceClient() : base(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:9000/tracer")) { }
   public void Write(string msg)
// TraceListener implementation
public class RemoteTraceListener : TraceListener
   public override void WriteLine(string message)
      Write(message + "\n");
   public override void Write(string message)
      using (var client = new RemoteTraceClient())
// Service implementation
public class TraceLog : ITraceWritable
   public void Write(string msg)
// usage in application to trace to
using (ServiceHost host = new ServiceHost(new TraceLog(), new Uri("net.tcp://localhost:9000/tracer")))
   host.AddServiceEndpoint(typeof(ITraceWritable), new NetTcpBinding(), "");
   Console.WriteLine("Press enter to exit");

// usage in application to trace from
System.Diagnostics.Trace.Listeners.Add(new RemoteTraceListener());
System.Diagnostics.Trace.TraceInformation("Added remote tracelistener");

Now my trace messages are directly visible in a console window. This is a great help with debugging. Of course this can be applied to existing applications via the config file….

      <add name="remote" type="[NameSpace].RemoteTraceListener, [Assembly]"/>

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , , . Bookmark the permalink.

2 Responses to Remote trace listener

  1. Dan M says:

    Thanks for the blurb. A little *.sln with your code would’ve been nice!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.