/[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 20:47:35	70
+++ trunk/TSAdminTool/Program.cs	2012/07/14 03:01:07	96
@@ -16,14 +16,18 @@
         [STAThread]
         static void Main()
         {
-            AppDomain currentDomain = AppDomain.CurrentDomain;
-            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
-            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
-            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
+            Logging.Initialize();
+            using (log4net.NDC.Push("Code executed from ATSAdmin.exe"))
+            {
+                AppDomain currentDomain = AppDomain.CurrentDomain;
+                currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
+                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
 
-            Application.EnableVisualStyles();
-            Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new frmAdmin());
+                Application.EnableVisualStyles();
+                Application.SetCompatibleTextRenderingDefault(false);
+                Application.Run(new frmAdmin());
+            }
         }
         static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
         {
@@ -44,8 +48,33 @@
                 List<string> strs = new List<string>();
                 using (log4net.NDC.Push(string.Format("{0}: ID={1} MESSAGE={2}{3}Diagnostics:{3}{4}", sql_ex.GetType().Name, sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString())))
                 {
-                    strs = Logging.GetMessagesFromThreadContextStack("NDC");
-                    Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                    Exception inner = sql_ex.InnerException;
+                    if (inner != null)
+                    {
+
+                        if (inner.GetType() == typeof(SqlException))
+                        {
+                            SqlException sql_inner = inner as SqlException;
+                            using (log4net.NDC.Push(string.Format("{0}: ID={1} MESSAGE={2}{3}Diagnostics:{3}{4}", sql_inner.GetType().Name, sql_inner.Number.ToString(), sql_inner.Message, System.Environment.NewLine, sql_inner.ToString())))
+                            {
+                                strs = Logging.GetMessagesFromThreadContextStack("NDC");
+                                Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                            }
+                        }
+                        else
+                        {
+                            using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", inner.GetType().Name, inner.Message, System.Environment.NewLine, inner.ToString())))
+                            {
+                                strs = Logging.GetMessagesFromThreadContextStack("NDC");
+                                Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                            }
+                        }
+                    }
+                    else
+                    {
+                        strs = Logging.GetMessagesFromThreadContextStack("NDC");
+                        Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                    }
                 }
                 StringBuilder builder = new StringBuilder();
                 foreach (string str in strs) { builder.AppendLine(str); }
@@ -58,8 +87,20 @@
                 List<string> strs = new List<string>();
                 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", e.GetType().Name, e.Message, System.Environment.NewLine, e.ToString())))
                 {
-                    strs = Logging.GetMessagesFromThreadContextStack("NDC");
-                    Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                    Exception inner = e.InnerException;
+                    if (inner != null)
+                    {
+                        using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", inner.GetType().Name, inner.Message, System.Environment.NewLine, inner.ToString())))
+                        {
+                            strs = Logging.GetMessagesFromThreadContextStack("NDC");
+                            Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                        }
+                    }
+                    else
+                    {
+                        strs = Logging.GetMessagesFromThreadContextStack("NDC");
+                        Logging.ATSAdminLog.Error("Encountered unhandled Exception");
+                    }
                 }
                 StringBuilder builder = new StringBuilder();
                 foreach (string str in strs) { builder.AppendLine(str); }

 

  ViewVC Help
Powered by ViewVC 1.1.22