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

Contents of /trunk/TSAdminTool/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 65 - (show annotations) (download)
Thu Jul 12 19:07:58 2012 UTC (9 years ago) by william
File size: 2342 byte(s)
also use bApplication.ThreadException in addition to AppDomain.UnhandledException

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 }

  ViewVC Help
Powered by ViewVC 1.1.22