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