/[AnywhereTS-MSSQL]/trunk/TSAdminTool/Program.cs
ViewVC logotype

Diff of /trunk/TSAdminTool/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/TSAdminTool/Program.cs	2012/07/12 16:21:35	51
+++ trunk/TSAdminTool/Program.cs	2012/07/12 16:29:51	52
@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Generic;
 using System.Windows.Forms;
+using log4net;
+using System.Data.SqlClient;
 
 namespace AnywhereTS
 {
@@ -12,9 +14,35 @@
         [STAThread]
         static void Main()
         {
+            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new frmAdmin());
         }
+
+        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+        {
+            Exception ex = (e.ExceptionObject as Exception);
+            if (ex == null)
+            {
+                Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
+                return;
+            }
+            if (e.ExceptionObject.GetType() == typeof(SqlException))
+            {
+                SqlException sql_ex = (ex as SqlException);
+                using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString())))
+                {
+                    Logging.ATSAdminLog.Error("Encountered unhandled SqlException");
+                }
+            }
+            else
+            {
+                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
+                {
+                    Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                }
+            }
+        }
     }
 }
\ No newline at end of file

 

  ViewVC Help
Powered by ViewVC 1.1.22