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

Diff of /trunk/TSControlPanel/Program.cs

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

--- trunk/TSControlPanel/Program.cs	2012/07/11 14:19:13	4
+++ trunk/TSControlPanel/Program.cs	2012/07/12 17:34:46	61
@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Windows.Forms;
+using System.Data.SqlClient;
 
 namespace AnywhereTS
 {
@@ -12,6 +13,10 @@
         [STAThread]
         static void Main()
         {
+            AppDomain currentDomain = AppDomain.CurrentDomain;
+            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
+
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
 
@@ -19,5 +24,29 @@
             objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.CONTROL_PANEL; // Select the mode to run the form in.
             Application.Run(objCustomDialogBox);            
         }
+        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
+        {
+            Exception e = (Exception)args.ExceptionObject;
+            if (e == null)
+            {
+                Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
+                return;
+            }
+            if (e.GetType() == typeof(SqlException))
+            {
+                SqlException sql_ex = (e 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("Exception: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                {
+                    Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                }
+            }
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22