Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2007

Tip: Looking for answers? Try searching our database.

Tracing in c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aks - 13 Jun 2007 19:57 GMT
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.
Stuart Davies - 17 Jun 2007 19:06 GMT
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"

> I've configured Trace switch in my app.config file:
> DebugLevel = new TraceSwitch("DebugLevel", "Trace Level for Entire
[quoted text clipped - 27 lines]
>
> Thanks in advance.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.