File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 55using System . Linq ;
66using System . Threading . Tasks ;
77using System . Windows ;
8+ using System . Windows . Threading ;
9+ using PSXPackagerGUI . Common ;
810
911namespace PSXPackagerGUI
1012{
@@ -13,5 +15,21 @@ namespace PSXPackagerGUI
1315 /// </summary>
1416 public partial class App : Application
1517 {
18+ public App ( )
19+ {
20+ this . DispatcherUnhandledException += OnDispatcherUnhandledException ;
21+ AppDomain . CurrentDomain . UnhandledException += CurrentDomainOnUnhandledException ;
22+ }
23+
24+ private void CurrentDomainOnUnhandledException ( object sender , UnhandledExceptionEventArgs e )
25+ {
26+ Logger . LogError ( $ "An unhandled exception occured.", e . ExceptionObject as Exception ) ;
27+ }
28+
29+ private void OnDispatcherUnhandledException ( object sender , DispatcherUnhandledExceptionEventArgs e )
30+ {
31+ Logger . LogError ( "An unhandled exception occured." , e . Exception ) ;
32+ e . Handled = true ;
33+ }
1634 }
1735}
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . IO ;
3+
4+ namespace PSXPackagerGUI . Common
5+ {
6+ public static class Logger
7+ {
8+ private static string LogPath = Path . Combine ( ApplicationInfo . AppPath , "logs.txt" ) ;
9+
10+ public static void LogError ( string message , Exception exception )
11+ {
12+ File . AppendAllText ( LogPath , $ "{ message } . { exception } \r \n ") ;
13+ }
14+
15+ public static void LogInfo ( string message )
16+ {
17+ File . AppendAllText ( LogPath , $ "{ message } \r \n ") ;
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change @@ -24,16 +24,24 @@ public partial class MainWindow : Window
2424
2525 public MainWindow ( )
2626 {
27+
28+ Logger . LogInfo ( "Starting up" ) ;
29+
2730 InitializeComponent ( ) ;
2831
32+ Logger . LogInfo ( "Creating Settings Page" ) ;
2933 _settings = new SettingsPage ( this ) ;
3034 _isFirstRun = _settings . IsFirstRun ;
3135
3236
37+ Logger . LogInfo ( "Creating Single Page" ) ;
3338 _singlePage = new SinglePage ( this , _settings . Model , _gameDb ) ;
39+
40+ Logger . LogInfo ( "Creating Batch Page" ) ;
3441 _batchPage = new BatchPage ( this , _settings . Model , _gameDb ) ;
3542 _singlePage . Model . PropertyChanged += ModelOnPropertyChanged ;
3643
44+ Logger . LogInfo ( "Creating Main Model" ) ;
3745 _model = new MainModel ( ) ;
3846
3947 DataContext = _model ;
You can’t perform that action at this time.
0 commit comments