且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

格式化跟踪输出

更新时间:2022-11-30 14:21:12

我建议你使用 log4net的相反,它具有更多的可定制性。

I suggest you use Log4Net instead, which has a lot more customizability.

另外你可以写它穿上了时间戳你自己的的TraceListener 的实施。您的可以的甚至能刚刚从 TextWriterTraceListener会派生并重写的WriteLine

Alternatively you could write your own TraceListener implementation which put the timestamps on for you. You may even be able just derive from TextWriterTraceListener and override Write and WriteLine:

public override void Write(string x)
{
     // Use whatever format you want here...
     base.Write(string.Format("{0:r}: {1}", DateTime.UtcNow, x));
}

public override void WriteLine(string x)
{
     // Use whatever format you want here...
     base.WriteLine(string.Format("{0:r}: {1}", DateTime.UtcNow, x));
}