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

Annotation of /trunk/TSAdminTool/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 52 - (hide annotations) (download)
Thu Jul 12 16:29:51 2012 UTC (8 years, 11 months ago) by william
File size: 1851 byte(s)
+ add support to log all unhandled exception(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22