|
-
February 12th, 2009, 08:20 AM
#1
How to use Trace
I want to use trace to file.
Code:
FileStream Log = new FileStream("Log.txt", FileMode.OpenOrCreate);
Trace.Listeners.Add(new TextWriterTraceListener(Log));
Trace.WriteLine("My Trace String To Log File");
Trace.Flush();
Log.Close();
The problem with the above codes is trace will always log to the file Log.txt.
How to call Trace with the file handler itself??, so that i can specify which file to log to when i do a Trace.
I tried using traceSource like the following, but it doesn';t work as well., the information is not even logged into file!!
Code:
{
string l_path = String.Format("c:\\mylog_{0}.txt", this.GetHashCode());
_log = new FileStream(String.Format(l_path), FileMode.Append);
}
if (_traceSrc == null)
{
_traceSrc = new TraceSource(this.GetHashCode().ToString());
_traceSrc.Listeners.Add(new TextWriterTraceListener(_log));
_traceSrc.TraceInformation(String.Format("Hello from {0}", GetHashCode()));
-
February 12th, 2009, 10:38 AM
#2
Re: How to use Trace
so you want to be able to log to multiple log files?
-
February 12th, 2009, 07:40 PM
#3
-
February 13th, 2009, 03:46 AM
#4
Re: How to use Trace
Same log in every file, or some information to one file and some to another? Than I'd recommend you to use some kind of logging framework, e.g. Logging Application Block of Microsoft's Enterprise Library.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|