static void Main() { // キャッチされなかったエラーの書き出し設定 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); System.Threading.Thread.GetDomain().UnhandledException += new UnhandledExceptionEventHandler(GetDomain_UnhandledException); // 【プログラム実行】 } //ThreadExceptionイベントハンドラ public static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { try { // ログ出力 Exception ex = (Exception)e.Exception; string sLogFile = System.IO.Path.Combine(Application.StartupPath, "ErrLog.txt"); using (System.IO.StreamWriter oLogFile = new System.IO.StreamWriter(sLogFile, true, System.Text.Encoding.UTF8)) { oLogFile.WriteLine(String.Format("[{0:yyyy/MM/dd HH:mm:ss}]", DateTime.Now)); oLogFile.WriteLine(ex.ToString()); oLogFile.WriteLine(); } // エラーメッセージを表示 OR.WinUI.Common.ORMsgBox.Error(null, ex.ToString(), "システムエラー"); } finally { //アプリケーションを終了する //Application.Exit(); } } //UnhandledExceptionイベントハンドラ private static void GetDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { // ログ出力 Exception ex = (Exception)e.ExceptionObject; string sLogFile = System.IO.Path.Combine(Application.StartupPath, "ErrLog.txt"); using (System.IO.StreamWriter oLogFile = new System.IO.StreamWriter(sLogFile, true, System.Text.Encoding.UTF8)) { oLogFile.WriteLine(String.Format("[{0:yyyy/MM/dd HH:mm:ss}]", DateTime.Now)); oLogFile.WriteLine(ex.ToString()); oLogFile.WriteLine(); } // エラーメッセージを表示 OR.WinUI.Common.ORMsgBox.Error(null, ex.ToString(), "システムエラー"); } finally { //アプリケーションを終了する //Application.Exit(); } }