I'm using TextWriterTraceListener
to log diagnostics messages to a text file. However I wan't also to log a timestamp of every trace message added. Is it possible to define a kind of formatter for the listener that would automatically add timestamps?
Currently I'm adding timestamps manually on every Trace.WriteLine()
call but this isn't very comfortable.
You could write your own TextWriterTraceListener subclass which overrides the WriteLine methods, decorates the line, and then passes the decorated string to the base class implementation to do the actual output.