471,570 Members | 902 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Viewing Event Log

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

}
Jan 10 '06 #1
2 1767
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

Jan 10 '06 #2
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!


"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

Jan 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.