I have created a debug listener to redirect the output from the Debug/Console window to a file(with a call stack), using the following code:
// Create a file for output .txt.
Stream debugFile = File.Create(fileName);
// create TextWriterTraceListener named "file"
TextWriterTraceListener debugWriter = new TextWriterTraceListener(debugFile, "file");
// add to debug listeners
// set callstack to be shown
Debug.Listeners["file"].TraceOutputOptions |= TraceOptions.Callstack;
// set auto-flush
Debug.AutoFlush = true;
but the output won't redirect to the file I specified, it is always empty. I am calling this from the constructor in my main form. Is the place where I'm calling it from a problem?
What I am trying to achieve here is to have the exceptions from the Debug output window placed in a file with a call stack, so that I can find them and correct them.
Anyone have any ideas?