I built the code in debug mode and it doesn't build the Trace.WriteLine
call. I looked at the disassembly during debugging session and that line
doesn't even exist. Is there any reason for that?
Thanks!
"albert braun" <bc***********************@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
For what it's worth, I pasted in this slightly modified version of your
code into the Main method of a simple console application, and it
worked just fine:
try
{
throw new ApplicationException("my test error
message");
}
catch (ApplicationException ex)
{
EventLogTraceListener myTraceListener = new
EventLogTraceListener("myEventLogSource");
// Add the event log trace listener to the collection.
Trace.Listeners.Add(myTraceListener);
// Write output to the event log.
Trace.WriteLine(string.Format("Error: {0}",
ex.Message));
}
Note that I found the message by opening up my Event Viewer, and
clicking on the "Application" node. I found the message in the right
pane. It was written with a Type field of "Information" and a Source
field of "myEventLogSource"
In other words, as far as i can tell, your code is correct, and I think
you're looking in the same place I looked. Sorry I can't point to the
problem! It works on my machine.
Grasping at straws here:
1. have you tried refreshing the Event Viewer by pressing F5 just after
this code is run?
2. are you sure the code in question is being executed?
regards,
albert braun