-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
43 lines (39 loc) · 1.32 KB
/
Copy pathProgram.cs
File metadata and controls
43 lines (39 loc) · 1.32 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
using System;
using System.IO;
using System.Windows.Forms;
namespace SaveManagerMSC
{
static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.ThreadException += (s, e) => LogUnhandledException(e.Exception);
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
if (e.ExceptionObject is Exception ex) LogUnhandledException(ex);
};
try
{
Application.Run(new MainForm());
}
catch (Exception ex)
{
LogUnhandledException(ex);
throw;
}
}
private static void LogUnhandledException(Exception ex)
{
try
{
string dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SaveManagerMSC");
if (!Directory.Exists(dataDir)) Directory.CreateDirectory(dataDir);
string logPath = Path.Combine(dataDir, "programmLog.txt");
File.AppendAllText(logPath, DateTime.Now.ToString("o") + " [FATAL] " + Errors.Tag(ErrCode.UNHANDLED_EXCEPTION) + " " + ex.ToString() + Environment.NewLine);
}
catch { }
}
}
}