Ok, so in my previous post I promised to have this up in a few days - and that was over two weeks ago :p Those two weeks became a rat race to finish a beta version of the web portal we're developing at work, as it was schedule for a big demonstration a few days ago. Well we got it (mostly) done, and we managed to demo it withouth any major hickups. So now that that's in the past, I've got my life back and will hopefully be able to continue blogging regularly :) Without any further ado then, here is the source code for the TcpTraceListener and client that goes with it, as promised:
Download the TcpTraceListener project.
Using the TcpTraceListener is quite easy: All you need to do is include the TcpTraceListener.dll with your application, and add the following lines to the app/web configuration file:
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="TcpTraceListener"
type="TcpTraceListener.TcpTraceListener, TcpTraceListener"
initializeData="127.0.0.1:9595" />
</listeners>
</trace>
</system.diagnostics>
You can leave the initializeData attribute blank, in which case it will default to localhost on port 9595.
Fire up your application, and any trace messages will now be sent to any TcpTraceListenerClient apps you've connected. For example:
Trace.WriteLine("Info: Application started.");
Notice the keyword at the beginning of the trace message, which the client will use to color-code the message in the log window. You can customize the keywords by changing the settings in the client. The default ones are "Info:", "Warning:" and "Error:".
Be warned that I consider the project to be a beta, and I've got a few things I'd like to improve on it. So use it at your own risk :)