@@ -15,18 +15,29 @@ public class LogFileProvider : ILoggerProvider
1515
1616 public LogFileProvider ( )
1717 {
18- if ( ! Directory . Exists ( Utils . UserAccessibleDataDirectory ) ) // Eat my ass windows
19- Directory . CreateDirectory ( Utils . UserAccessibleDataDirectory ) ;
18+ try
19+ {
20+ if ( ! Directory . Exists ( Utils . UserAccessibleDataDirectory ) ) // Eat my ass windows
21+ Directory . CreateDirectory ( Utils . UserAccessibleDataDirectory ) ;
2022
21- CleanupOldLogFiles ( ) ;
23+ CleanupOldLogFiles ( ) ;
2224
23- var timestamp = DateTime . Now . ToString ( "yyyy-MM-dd_HH-mm-ss" ) ;
24- var logFileName = $ "baballonia_desktop.{ timestamp } .log";
25- var logPath = Path . Combine ( Utils . UserAccessibleDataDirectory , logFileName ) ;
25+ var timestamp = DateTime . Now . ToString ( "yyyy-MM-dd_HH-mm-ss" ) ;
26+ var logFileName = $ "baballonia_desktop.{ timestamp } .log";
27+ var logPath = Path . Combine ( Utils . UserAccessibleDataDirectory , logFileName ) ;
2628
27- var file = new FileStream ( logPath , FileMode . Create , FileAccess . Write , FileShare . ReadWrite , 4096 ,
28- FileOptions . WriteThrough ) ;
29- _writer = new StreamWriter ( file ) ;
29+ var file = new FileStream ( logPath , FileMode . Create , FileAccess . Write , FileShare . ReadWrite , 4096 ,
30+ FileOptions . WriteThrough ) ;
31+ _writer = new StreamWriter ( file ) ;
32+ }
33+ catch
34+ {
35+ // If we can't create the log file (e.g. OneDrive Documents folder
36+ // is unavailable), continue without file logging rather than
37+ // crashing the entire application. CreateLogger will return
38+ // NullLogger.Instance when _writer is null.
39+ _writer = null ;
40+ }
3041 }
3142
3243 private void CleanupOldLogFiles ( )
0 commit comments