c# - Formatting trace output -
I am using TextWriterTraceListener
to log diagnostic messages into a text file. However I do not want to add a tickload of every trace message to log in too. Is it possible for a listener to define a type of formatter, which will automatically add the timestamp?
Currently I'm manually adding timestamps to every trace. Written ()
call but this ins is not very comfortable.
I recommend that you use it instead, which has more optimization capability.
Alternatively, you can write your own trace listener
implementation that puts the timestamp for you. can be from TextWriterTraceListener
and override type
and WriteLine
:
< Write Code> Public Override Zero (string x) {// Use the format you want here ... base.Write (string.Format ("{0: r}: {1}", DateTime.Utakano, X)); } Use the public override zero WriteLine (string x) {// whatever format you want ... base.WriteLine (string.Format ("{0: r}: {1}", DateTime.UtcNow, x) ); }
Comments
Post a Comment