-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProgram.cs
69 lines (60 loc) · 1.92 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace WinformExampleCore
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
#if DEBUG
Debugger.Launch();
#endif
#if LOGGING && TRACE
TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log");
logger.TraceOutputOptions = TraceOptions.DateTime;
Trace.Listeners.Add(logger);
Trace.AutoFlush = true;
Trace.TraceInformation("Logging started");
#endif
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
string[] args = Environment.GetCommandLineArgs();
Application.Run(new MainForm(args));
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
LogUnhandledException(e.Exception);
Trace.TraceInformation("Shutting down");
Application.Exit();
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
LogUnhandledException(e.ExceptionObject as Exception);
Trace.TraceInformation("Shutting down");
Application.Exit();
}
static void LogUnhandledException(Exception e)
{
Trace.TraceError(e.Message);
using (StreamWriter sw = new StreamWriter("Critical exceptions.log", true))
{
sw.WriteLine($"{DateTime.Now.ToUniversalTime()} - {e.Message}");
sw.WriteLine(e.StackTrace);
sw.WriteLine();
sw.Close();
}
if (e.InnerException != null) LogUnhandledException(e.InnerException);
}
}
}