Tracing in c#

G

Guest

I've configured Trace switch in my app.config file:
DebugLevel = new TraceSwitch("DebugLevel", "Trace Level for Entire
Application");

and have created and initialized a trace listener in my application code:
FileStream m_Stream = new FileStream(m_logFile, FileMode.Append,
FileAccess.Write);
myTextListener = new TextWriterTraceListener(m_Stream);
Trace.Listeners.Add(myTextListener);

usage in my code:
Trace.WriteLine(DebugLevel.TraceInfo, String.Format("{0} Trace Level={1}",
DateTime.Now, DebugLevel.Level));

output in the log file:
6/13/2007 10:34:49 AM Trace Level=Verbose: True

format of the output I would like to see:
6/13/2007 10:34:49 AM Trace Level=Verbose
(don't want to see any ": True" or ":False" appended to each msg)

The ": True" or ": False" go away if I re-write my code as:
Trace.WriteLine(DateTime.Now, DebugLevel.TraceInfo);
However, I would like to use the String.Format("{0} Trace Level={1}", .....)
as it is very handy with multiple variables to be written to a log file.

Can anyone help me get rid of this ": True" or ": False" in the Trace msgs
in my logfile ?

Thanks in advance.
 
S

Stuart Davies

One quick/simple solution would be to just strip off everything after and
including the colon in the following manner:

Trace.WriteLine(DebugLevel.TraceInfo, String.Format("{0} Trace Level={1}",
DateTime.Now, DebugLevel.Level.ToString.Split(':')[0]));

Cheers
Stuart
"Is facio in meus apparatus"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top