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

Annotation of /trunk/TSAdminTool/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (hide annotations) (download)
Thu Jul 12 17:34:46 2012 UTC (8 years, 11 months ago) by william
File size: 1980 byte(s)
+ more wip for unhandled exception

1 william 4 using System;
2     using System.Collections.Generic;
3     using System.Windows.Forms;
4 william 52 using log4net;
5     using System.Data.SqlClient;
6 william 4
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 william 61 {
17     AppDomain currentDomain = AppDomain.CurrentDomain;
18     currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
19     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
20    
21 william 4 Application.EnableVisualStyles();
22     Application.SetCompatibleTextRenderingDefault(false);
23     Application.Run(new frmAdmin());
24     }
25 william 61 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
26     {
27     Exception e = (Exception)args.ExceptionObject;
28     if (e == null)
29     {
30     Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
31     return;
32     }
33     if (e.GetType() == typeof(SqlException))
34     {
35     SqlException sql_ex = (e as SqlException);
36     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())))
37     {
38     Logging.ATSAdminLog.Error("Encountered unhandled SqlException");
39     }
40     }
41     else
42     {
43     using (log4net.NDC.Push(string.Format("Exception: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
44     {
45     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
46     }
47     }
48     }
49 william 4 }
50     }

  ViewVC Help
Powered by ViewVC 1.1.22