Ugh. I obviously don't understand the correct way to use this thing!
I have several #if(DEBUG) code blocks to write to a file ErrorLog.txt
to troubleshoot why and what exceptions are being encountered.
So in my class this is defined:
static FileStream traceLog = new FileStream("Err orLog.txt",
FileMode.OpenOr Create, FileAccess.Writ e);
static TextWriterTrace Listener traceListener = new
TextWriterTrace Listener(traceL og);
then in the same class I have this method
private static void Logger(string errorMessage)
{
// Create a text file to write messages to
// Create a TextWriterTrace Listener
//TextWriterTrace Listener traceListener = new
TextWriterTrace Listener(traceL og);
// Add the traceListener to the Trace.Listeners collection
Trace.Listeners .Add(traceListe ner);
Trace.WriteLine (errorMessage);
//Trace.Listeners .Remove(traceLi stener);
Trace.Flush();
}
At various places in my program... I make this call:
Logger("Excepti on thrown from Logout()");
Logger(ex.Messa ge.ToString());
And here's the problem! My file, the first time Logger is called no
problem errorMessage is written to the file.
the second time it's called, it creates two entries of the
errorMessage to the file. The third time... you get the point.
Here's a sample file: (each of the items only happened once, but was
written multiple times)
MAILSERVER=some configfilesetti ng
Connection Made
Connection Made
Login Success
Login Success
Login Success
MailCount = 0
MailCount = 0
MailCount = 0
MailCount = 0
Ideas? I can't figure out why this is happening... when stepping into
the debugger, I don' see this data replicated, and I'm not seeing it
written duplicate