Reputation: 11304
Below code is writing trace on a text file correctly, but for each program execution (multi-threaded and loop), a different file is generated.
how to make a single file output with all the content. Thanks!
private static void InitiateTracer()
{
Trace.Listeners.Clear();
var dir = AppDomain.CurrentDomain.BaseDirectory;
var twtl = new TextWriterTraceListener("log.txt")
{
Name = "TextLogger",
TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime
};
var ctl = new ConsoleTraceListener(false) { TraceOutputOptions = TraceOptions.DateTime };
Trace.Listeners.Add(twtl);
Trace.Listeners.Add(ctl);
Trace.AutoFlush = true;
}
Upvotes: 0
Views: 337
Reputation: 1449
You can try this
TextWriterTraceListener = new TextWriterTraceListener(new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite));
Upvotes: 1