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

Contents of /trunk/TSAdminTool/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (show annotations) (download)
Thu Jul 12 19:34:37 2012 UTC (8 years, 11 months ago) by william
File size: 3361 byte(s)
Clone NDC stack within using statemnt

1 using System;
2 using System.Collections.Generic;
3 using System.Windows.Forms;
4 using log4net;
5 using System.Data.SqlClient;
6 using System.Collections;
7 using System.Text;
8
9 namespace AnywhereTS
10 {
11 static class Program
12 {
13 /// <summary>
14 /// The main entry point for the application.
15 /// </summary>
16 [STAThread]
17 static void Main()
18 {
19 AppDomain currentDomain = AppDomain.CurrentDomain;
20 currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
21 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
22 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
23
24 Application.EnableVisualStyles();
25 Application.SetCompatibleTextRenderingDefault(false);
26 Application.Run(new frmAdmin());
27 }
28 static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
29 {
30 CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, false));
31 }
32 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
33 {
34 Exception e = (Exception)args.ExceptionObject;
35 if (e == null)
36 {
37 Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
38 return;
39 }
40 if (e.GetType() == typeof(SqlException))
41 {
42 SqlException sql_ex = (e as SqlException);
43 Stack stack = new Stack();
44 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())))
45 {
46 stack = log4net.NDC.CloneStack();
47 Logging.ATSAdminLog.Error("Encountered unhandled SqlException");
48 }
49 List<object> strs = new List<object>(stack.ToArray());
50 strs.Reverse();
51 StringBuilder builder = new StringBuilder();
52 foreach (object str in strs) { builder.AppendLine(str.ToString()); }
53 builder.AppendLine("Encountered unhandled Exception");
54 MessageBox.Show(builder.ToString());
55 }
56 else
57 {
58 Stack stack = new Stack();
59 using (log4net.NDC.Push(string.Format("Exception: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
60 {
61 stack = log4net.NDC.CloneStack();
62 Logging.ATSAdminLog.Error("Encountered unhandled Exception");
63 }
64 List<object> strs = new List<object>(stack.ToArray());
65 strs.Reverse();
66 StringBuilder builder = new StringBuilder();
67 foreach (object str in strs) { builder.AppendLine(str.ToString()); }
68 builder.AppendLine("Encountered unhandled Exception");
69 MessageBox.Show(builder.ToString());
70 }
71 }
72 }
73 }

  ViewVC Help
Powered by ViewVC 1.1.22