Sunday, April 09, 2006

Ever wonder what exceptions were generated during program execution.

Windows provides a readymade class EventLog to log your exceptions as eventlog.

a sample code to how to use EventLog

// this contains the EventLog class
using System.Diagnostics ;

try
{
// some code
}
catch(Exception _ex)
{
EventLog.WriteEntry("source", _ex.ToString(), EvenLogEntryType.Error, 0, 0, null) ;
// your code
}

Summary:

The WriteEntry method writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log (using the specified registered event source) and appends binary data to the message.