AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
void currentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception exception;
exception = e.ExceptionObject as Exception;
if (exception == null)
{
if (e.ExceptionObject != null)
{
EventLog log = new EventLog();
log.Source = "app";
log.WriteEntry(e.ExceptionObject.ToString() + " Terminating:" + e.IsTerminating.ToString(), EventLogEntryType.Error);
}
}
else
{
EventLog log = new EventLog();
log.Source = "app";
log.WriteEntry("Message:" + exception.Message + " Source:" + exception.Source + " StackTrace:" + exception.StackTrace + " Terminating:" + e.IsTerminating.ToString(), EventLogEntryType.Error);
}
}
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
void currentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception exception;
exception = e.ExceptionObject as Exception;
if (exception == null)
{
if (e.ExceptionObject != null)
{
EventLog log = new EventLog();
log.Source = "app";
log.WriteEntry(e.ExceptionObject.ToString() + " Terminating:" + e.IsTerminating.ToString(), EventLogEntryType.Error);
}
}
else
{
EventLog log = new EventLog();
log.Source = "app";
log.WriteEntry("Message:" + exception.Message + " Source:" + exception.Source + " StackTrace:" + exception.StackTrace + " Terminating:" + e.IsTerminating.ToString(), EventLogEntryType.Error);
}
}