@@ -15,17 +15,19 @@ public static void AddHandlers()
15
15
{
16
16
AppDomain . CurrentDomain . UnhandledException += ( sender , args ) =>
17
17
{
18
- var filePath = string . Format ( "./UnhandledException{0}.json" , DateTime . Now . ToShortDateString ( ) ) ;
19
- File . WriteAllText ( filePath , JsonConvert . SerializeObject ( args . ExceptionObject ) ) ;
20
- MessageBox . Show ( string . Format ( "An Unhandled Exception was Caught and Logged to:\r \n {0}" , filePath ) , "Exception Caught" ) ;
18
+ Directory . CreateDirectory ( "./Logs" ) ;
19
+ var filePath = string . Format ( "Logs/UnhandledException{0}.json" , DateTime . Now . ToShortDateString ( ) . Replace ( "/" , "-" ) ) ;
20
+ File . WriteAllText ( "./" + filePath , JsonConvert . SerializeObject ( args . ExceptionObject , Formatting . Indented ) ) ;
21
+ MessageBox . Show ( string . Format ( "An Unhandled Exception was Caught and Logged to:\r \n {0}" , filePath ) , "Exception Caught" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
21
22
} ;
22
23
23
24
24
25
Application . ThreadException += ( sender , args ) =>
25
26
{
26
- var filePath = string . Format ( "./ThreadException{0}.json" , DateTime . Now . ToShortDateString ( ) ) ;
27
- File . WriteAllText ( string . Format ( "./ThreadException{0}.json" , DateTime . Now . ToShortDateString ( ) ) , JsonConvert . SerializeObject ( args . Exception ) ) ;
28
- MessageBox . Show ( string . Format ( "An Unhandled Thread Exception was Caught and Logged to:\r \n {0}" , filePath ) , "Thread Exception Caught" ) ;
27
+ Directory . CreateDirectory ( "./Logs" ) ;
28
+ var filePath = string . Format ( "Logs/ThreadException{0}.json" , DateTime . Now . ToShortDateString ( ) . Replace ( "/" , "-" ) ) ;
29
+ File . WriteAllText ( "./" + filePath , JsonConvert . SerializeObject ( args . Exception , Formatting . Indented ) ) ;
30
+ MessageBox . Show ( string . Format ( "An Unhandled Thread Exception was Caught and Logged to:\r \n {0}" , filePath ) , "Thread Exception Caught" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
29
31
} ;
30
32
}
31
33
}
0 commit comments