1- global using Stone_Red_Utilities . Logging ;
2-
3- using Stone_Red_C_Sharp_Utilities . Logging ;
1+ using CuteUtils . Logging ;
42
53using System ;
64using System . IO ;
@@ -17,28 +15,65 @@ public partial class App : Application
1715 public const string AppGuid = "{{61FE5CE9-47C3-4255-A1F4-5BCF4ACA0879}" ;
1816
1917 public const string AppName = "Desktop Magic" ;
20- private readonly string logFilePath ;
18+
19+ private static readonly string logFilePath = Path . Combine ( ApplicationDataPath , $ "{ AppName } .log") ;
2120
2221 private readonly Thread ? eventThread ;
22+
2323 private readonly EventWaitHandle eventWaitHandle ;
2424
25- private readonly Logger logger = new Logger ( ) ;
26- public static string ApplicationDataPath { get ; } = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "StoneRed" , AppName ) ;
25+ public static Logger Logger { get ; } = new Logger ( )
26+ {
27+ Config = new ( )
28+ {
29+ FatalConfig = new OutputConfig ( )
30+ {
31+ ConsoleColor = ConsoleColor . DarkRed ,
32+ LogTarget = LogTarget . DebugConsole | LogTarget . File ,
33+ FilePath = logFilePath
34+ } ,
35+ ErrorConfig = new OutputConfig ( )
36+ {
37+ ConsoleColor = ConsoleColor . Red ,
38+ LogTarget = LogTarget . DebugConsole | LogTarget . File ,
39+ FilePath = logFilePath
40+ } ,
41+ WarnConfig = new OutputConfig ( )
42+ {
43+ ConsoleColor = ConsoleColor . Yellow ,
44+ LogTarget = LogTarget . DebugConsole | LogTarget . File ,
45+ FilePath = logFilePath
46+ } ,
47+ InfoConfig = new OutputConfig ( )
48+ {
49+ ConsoleColor = ConsoleColor . White ,
50+ LogTarget = LogTarget . DebugConsole | LogTarget . File ,
51+ FilePath = logFilePath
52+ } ,
53+ DebugConfig = new OutputConfig ( )
54+ {
55+ ConsoleColor = ConsoleColor . Gray ,
56+ LogTarget = LogTarget . DebugConsole ,
57+ } ,
58+ FormatConfig = new FormatConfig ( )
59+ {
60+ DebugConsoleFormat = $ "> {{{LogFormatType.DateTime}:HH:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\n at {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
61+ }
62+ }
63+ } ;
2764
28- public static Logger Logger => ( ( App ) Current ) . logger ;
65+ public static string ApplicationDataPath => Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "StoneRed" , AppName ) ;
2966
3067 public App ( )
3168 {
32- logFilePath = ApplicationDataPath + "\\ log.log" ;
33-
3469 // Setup global event handler
3570 eventWaitHandle = new EventWaitHandle ( false , EventResetMode . AutoReset , AppGuid , out bool createdNew ) ;
3671
3772 //check if creating new was successful
3873 if ( ! createdNew )
3974 {
4075 Setup ( false ) ;
41- Logger . Log ( "Shutting down because other instance already running." , "Setup" , LogSeverity . Warn ) ;
76+ Logger . LogWarn ( "Shutting down because other instance already running." , source : "Setup" ) ;
4277 //Shutdown Application
4378 _ = eventWaitHandle . Set ( ) ;
4479 Current . Shutdown ( ) ;
@@ -71,50 +106,13 @@ private void Setup(bool clearLogFile)
71106 {
72107 AppDomain . CurrentDomain . UnhandledException += CurrentDomain_UnhandledException ;
73108
74- Logger . Config = new LogConfig ( )
75- {
76- FatalConfig = new OutputConfig ( )
77- {
78- Color = ConsoleColor . DarkRed ,
79- LogTarget = LogTarget . DebugConsole | LogTarget . File ,
80- FilePath = logFilePath
81- } ,
82- ErrorConfig = new OutputConfig ( )
83- {
84- Color = ConsoleColor . Red ,
85- LogTarget = LogTarget . DebugConsole | LogTarget . File ,
86- FilePath = logFilePath
87- } ,
88- WarnConfig = new OutputConfig ( )
89- {
90- Color = ConsoleColor . Yellow ,
91- LogTarget = LogTarget . DebugConsole | LogTarget . File ,
92- FilePath = logFilePath
93- } ,
94- InfoConfig = new OutputConfig ( )
95- {
96- Color = ConsoleColor . White ,
97- LogTarget = LogTarget . DebugConsole | LogTarget . File ,
98- FilePath = logFilePath
99- } ,
100- DebugConfig = new OutputConfig ( )
101- {
102- Color = ConsoleColor . Gray ,
103- LogTarget = LogTarget . DebugConsole ,
104- } ,
105- FormatConfig = new FormatConfig ( )
106- {
107- DebugConsoleFormat = $ "> {{{LogFormatType.DateTime}:HH:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\n at {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
108- }
109- } ;
110-
111109 try
112110 {
113111 if ( ! Directory . Exists ( ApplicationDataPath ) )
114112 {
115113 _ = Directory . CreateDirectory ( ApplicationDataPath ) ;
116114 }
117- Logger . Log ( "Created ApplicationData Folder" , "Main" ) ;
115+ Logger . LogInfo ( "Created ApplicationData Folder" , source : "Main" ) ;
118116 }
119117 catch ( Exception ex )
120118 {
@@ -127,12 +125,12 @@ private void Setup(bool clearLogFile)
127125 Logger . ClearLogFile ( LogSeverity . Info ) ;
128126 }
129127
130- Logger . Log ( "Log setup complete", "Setup" ) ;
128+ Logger . LogInfo ( "Setup complete", source : "Setup" ) ;
131129 }
132130
133131 private void CurrentDomain_UnhandledException ( object sender , UnhandledExceptionEventArgs e )
134132 {
135133 Exception exception = ( Exception ) e . ExceptionObject ;
136- Logger . Log ( exception + ( e . IsTerminating ? "\t Process terminating!" : "" ) , exception . Source , LogSeverity . Fatal ) ;
134+ Logger . LogFatal ( exception + ( e . IsTerminating ? "\t Process terminating!" : "" ) , source : exception . Source ?? "Unknown" ) ;
137135 }
138136}
0 commit comments