As we discussed here, we can use Trace.WriteLine
to write logs to both command-line console and a chosen file.
My need is to sometimes use Trace.WriteLine
to print ONLY to file, NOT to console.
How can we reach that?
p.s.
Here is how I init the listener
#region init logging
Trace.Listeners.Clear();
var logFile = Path.Combine("Path", "to", "log file");
var twtl = new TextWriterTraceListener(logFile);
twtl.Name = "TextLogger";
twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;
var ctl = new ConsoleTraceListener(false);
ctl.TraceOutputOptions = TraceOptions.DateTime;
Trace.Listeners.Add(twtl);
Trace.Listeners.Add(ctl);
Trace.AutoFlush = true;
//Trace.WriteLine("The first line to be in the logfile and on the console.");
#endregion