-
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()));
-
Re: How to use Trace
so you want to be able to log to multiple log files?
-
Re: How to use Trace
-
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.