-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
46 lines (45 loc) · 1.87 KB
/
Copy pathProgram.cs
File metadata and controls
46 lines (45 loc) · 1.87 KB
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
using System;
using System.Windows.Forms;
using SymptomCheckerApp.Services;
namespace SymptomCheckerApp
{
internal static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
var logDir = Path.Combine(AppContext.BaseDirectory, "logs");
var logger = new LoggerService(logDir);
logger.Info("Application starting");
Application.ThreadException += (s, e) =>
{
try { MessageBox.Show(e.Exception.ToString(), "Unhandled UI Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); }
catch { }
try { logger.Error("Unhandled UI thread exception", e.Exception); } catch { }
};
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
try { MessageBox.Show((e.ExceptionObject?.ToString() ?? "Unknown error"), "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); }
catch { }
try { logger.Error("Unhandled domain exception", e.ExceptionObject as Exception); } catch { }
};
try
{
var form = new UI.MainForm();
logger.Info("MainForm created");
Application.Run(form);
}
catch (Exception ex)
{
try { MessageBox.Show(ex.ToString(), "Startup Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); }
catch { }
try { logger.Error("Startup exception", ex); } catch { }
}
try { logger.Info("Application exiting"); } catch { }
}
}
}