the default implementation shows the output as ': : ', now i dont want this format, i want to cut off the sourcename and eventid because it' s totally useless for me. is there any easy way i can accomplis开发者_开发问答h that?
my current workaround is to derive from TextWriterTraceListener and override the TrackEvent method. use reflector to copy the default implementation and just remove the writerHeader function call.
you can create derived class from TextWriterTraceListener and override TraceEvent to change output format. It would be better to override all TraceEvent methods. e.g.
class TextWriterTraceListenerCustomOutput:TextWriterTraceListener
{
public TextWriterTraceListenerCustomOutput(string fileName):base(fileName)
{
}
public override void Write(string message)
{
base.Write(String.Format("[{0}]:{1}",DateTime.Now,message));
}
public override void WriteLine(string message)
{
base.WriteLine(String.Format("[{0}]:{1}", DateTime.Now, message));
}
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
{
//base.TraceEvent(eventCache, source, eventType, id, message);
if(String.IsNullOrEmpty(message)) return;
WriteLine(String.Format("{0}:{1}:{2}:{3}",source, eventType,Enum.GetName(typeof(LogId),id),message.Replace("\r",string.Empty).Replace("\n",string.Empty)));
}
}
精彩评论