From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。
---
HotelPms.Share.Windows/Util/UnhandledExceptionListener.cs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/HotelPms.Share.Windows/Util/UnhandledExceptionListener.cs b/HotelPms.Share.Windows/Util/UnhandledExceptionListener.cs
new file mode 100644
index 0000000..95ea7d6
--- /dev/null
+++ b/HotelPms.Share.Windows/Util/UnhandledExceptionListener.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms;
+using System.IO;
+
+namespace HotelPms.Share.Windows.Util
+{
+ public class UnhandledExceptionListener
+ {
+ public static void Execute()
+ {
+ Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
+ Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+ if (Application.StartupPath.CompareTo(Environment.CurrentDirectory) != 0) { Environment.CurrentDirectory = Application.StartupPath; }
+ }
+
+ private static void WriteUnhandledExceptionLog(object data, string title)
+ {
+ try
+ {
+ string file = Application.StartupPath + @"\UnhandledException.log";
+
+ if (File.Exists(file))
+ {
+ FileInfo fileInfo = new FileInfo(file);
+ if (fileInfo.Length > 1024 * 1024)
+ {
+ string bkfile = string.Format(@"\UnhandledException{0}.log", DateTime.Now.ToString("yyyyMMddHHmmss"));
+ File.Copy(file, bkfile, true);
+ File.Delete(file);
+ }
+ }
+
+ using (System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Append, System.IO.FileAccess.Write))
+ {
+ using (System.IO.StreamWriter w = new System.IO.StreamWriter(fs, System.Text.Encoding.UTF8))
+ {
+ w.WriteLine(string.Format("�y{0}�z{2}�F{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss fff"), data, title));
+ }
+ }
+ }
+ catch { }
+ }
+
+ private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
+ {
+ WriteUnhandledExceptionLog(e.Exception, "Application_ThreadException");
+ }
+
+ private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+ {
+ WriteUnhandledExceptionLog(e.ExceptionObject, "CurrentDomain_UnhandledException" + "�F" + e.IsTerminating.ToString());
+ }
+ }
+}
--
Gitblit v1.10.0