17
17
using System . Text . Json ;
18
18
using System . Text . Json . Serialization ;
19
19
using Microsoft . Extensions . Logging ;
20
+ using static Terminal . Gui . ConfigurationManager ;
21
+ using Command = Terminal . Gui . Command ;
20
22
using Serilog ;
21
23
using Serilog . Core ;
22
24
using Serilog . Events ;
23
- using Terminal . Gui ;
24
- using static Terminal . Gui . ConfigurationManager ;
25
- using Command = Terminal . Gui . Command ;
26
25
using ILogger = Microsoft . Extensions . Logging . ILogger ;
27
26
using RuntimeEnvironment = Microsoft . DotNet . PlatformAbstractions . RuntimeEnvironment ;
27
+ using Terminal . Gui ;
28
28
29
29
#nullable enable
30
30
@@ -171,7 +171,7 @@ private static int Main (string [] args)
171
171
// what's the app name?
172
172
_logFilePath = $ "{ LOGFILE_LOCATION } /{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name } .log";
173
173
Option < string > debugLogLevel = new Option < string > ( "--debug-log-level" , $ "The level to use for logging (debug console and { _logFilePath } )") . FromAmong (
174
- Enum . GetNames < LogEventLevel > ( )
174
+ Enum . GetNames < LogLevel > ( )
175
175
) ;
176
176
debugLogLevel . SetDefaultValue ( "Warning" ) ;
177
177
debugLogLevel . AddAlias ( "-dl" ) ;
@@ -234,9 +234,25 @@ private static int Main (string [] args)
234
234
return 0 ;
235
235
}
236
236
237
+ private static LogEventLevel LogLevelToLogEventLevel ( LogLevel logLevel )
238
+ {
239
+ return logLevel switch
240
+ {
241
+ LogLevel . Trace => LogEventLevel . Verbose ,
242
+ LogLevel . Debug => LogEventLevel . Debug ,
243
+ LogLevel . Information => LogEventLevel . Information ,
244
+ LogLevel . Warning => LogEventLevel . Warning ,
245
+ LogLevel . Error => LogEventLevel . Error ,
246
+ LogLevel . Critical => LogEventLevel . Fatal ,
247
+ LogLevel . None => LogEventLevel . Fatal , // Default to Fatal if None is specified
248
+ _ => LogEventLevel . Fatal // Default to Information for any unspecified LogLevel
249
+ } ;
250
+ }
251
+
237
252
private static ILogger CreateLogger ( )
238
253
{
239
254
// Configure Serilog to write logs to a file
255
+ _logLevelSwitch . MinimumLevel = LogLevelToLogEventLevel ( Enum . Parse < LogLevel > ( _options . DebugLogLevel ) ) ;
240
256
Log . Logger = new LoggerConfiguration ( )
241
257
. MinimumLevel . ControlledBy ( _logLevelSwitch )
242
258
. Enrich . FromLogContext ( ) // Enables dynamic enrichment
@@ -1295,19 +1311,19 @@ private List<MenuItem []> CreateLoggingMenuItems ()
1295
1311
[ SuppressMessage ( "Style" , "IDE1006:Naming Styles" , Justification = "<Pending>" ) ]
1296
1312
private MenuItem [ ] CreateLoggingFlagsMenuItems ( )
1297
1313
{
1298
- string [ ] logLevelMenuStrings = Enum . GetNames < LogEventLevel > ( ) . Select ( n => n = "_" + n ) . ToArray ( ) ;
1299
- LogEventLevel [ ] logLevels = Enum . GetValues < LogEventLevel > ( ) ;
1314
+ string [ ] logLevelMenuStrings = Enum . GetNames < LogLevel > ( ) . Select ( n => n = "_" + n ) . ToArray ( ) ;
1315
+ LogLevel [ ] logLevels = Enum . GetValues < LogLevel > ( ) ;
1300
1316
1301
1317
List < MenuItem ? > menuItems = new ( ) ;
1302
1318
1303
- foreach ( LogEventLevel logLevel in logLevels )
1319
+ foreach ( LogLevel logLevel in logLevels )
1304
1320
{
1305
1321
var item = new MenuItem
1306
1322
{
1307
1323
Title = logLevelMenuStrings [ ( int ) logLevel ]
1308
1324
} ;
1309
1325
item . CheckType |= MenuItemCheckStyle . Checked ;
1310
- item . Checked = Enum . Parse < LogEventLevel > ( _options . DebugLogLevel ) == logLevel ;
1326
+ item . Checked = Enum . Parse < LogLevel > ( _options . DebugLogLevel ) == logLevel ;
1311
1327
1312
1328
item . Action += ( ) =>
1313
1329
{
@@ -1319,7 +1335,7 @@ private MenuItem [] CreateLoggingFlagsMenuItems ()
1319
1335
if ( item . Title == logLevelMenuStrings [ ( int ) logLevel ] && item . Checked == false )
1320
1336
{
1321
1337
_options . DebugLogLevel = Enum . GetName ( logLevel ) ! ;
1322
- _logLevelSwitch . MinimumLevel = Enum . Parse < LogEventLevel > ( _options . DebugLogLevel ) ;
1338
+ _logLevelSwitch . MinimumLevel = LogLevelToLogEventLevel ( Enum . Parse < LogLevel > ( _options . DebugLogLevel ) ) ;
1323
1339
item . Checked = true ;
1324
1340
}
1325
1341
0 commit comments