winform中Log4Net使用笔记
static class Program { static log4net.ILog LOG = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { //捕获未处理异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FormMain()); } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { LOG.Error(e.Exception); //throw new Exception("线程未知异常", e.Exception); MessageBox.Show(e.Exception.Message, "线程异常", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception ex = e.ExceptionObject as Exception; LOG.Error(ex); MessageBox.Show(ex.Message, "应用程序异常", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70250.html