Using Tracing with WCF Service Log

Using tracing can be very beneficial especially when the application has already been deployed and we need to figure out why it doesn't work. Useless errors of type: 500 don't give any meaningful results, so I decided to use System.Diagnostics to help me track down the errors.

Logging

There are two important (and very simplifed definitions):

  1. TraceSource - is used to add messages
  2. TraceListener - is used to output those messages to a file

Note: It is the name that is used to identify the TraceSource, so the same TraceSource can be used across different classes and even different projects, just give them the same name.

Now in order to add a new message:

There are different types messages that can be outputted.

There are several really cool articles that describe how to this functionally effectively.

Outputting

Now we need a trace listner to save our output to a given location

This should save all the files to c:\logs\service.svclog. I generally like to keep a backlog of these. It proves useful if you want to find a pattern in behavior. Microsoft doesn't seem to have implemented something like this. It is beneficial to implement your own TraceListener. Well... It has already been done by hunderds of people. A good example you can find here: http://www.codeproject.com/Articles/30956/A-Rolling-XmlWriterTraceListener

Leave Comment

Your email address will not be published.

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box