Viewing Event Log

Z

Zen

Hi,

Would someone please point out where I can go to view the event log for the
following code? I thought it was the Event Viewer | Application in the
Computer Management but I didn't see it. thanks!

catch(Exception ex)

{

// Create a trace listener for the event log.

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 ) );

}
 
A

albert braun

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
 
Z

Zen

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top