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);
            }
        }
posted on 2008-05-22 09:34  大斌锅  阅读(276)  评论(0编辑  收藏  举报