File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed
src/Serilog.Settings.Configuration/Settings/Configuration Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 1- using Microsoft . Extensions . Configuration ;
1+ using System ;
2+
3+ using Microsoft . Extensions . Configuration ;
24using Serilog ;
35using System . IO ;
46
@@ -10,14 +12,18 @@ public static void Main(string[] args)
1012 {
1113 var configuration = new ConfigurationBuilder ( )
1214 . SetBasePath ( Directory . GetCurrentDirectory ( ) )
13- . AddJsonFile ( "appsettings.json" )
15+ . AddJsonFile ( path : "appsettings.json" , optional : false , reloadOnChange : true )
1416 . Build ( ) ;
1517
1618 var logger = new LoggerConfiguration ( )
1719 . ReadFrom . Configuration ( configuration )
1820 . CreateLogger ( ) ;
1921
20- logger . Information ( "Hello, world!" ) ;
22+ do
23+ {
24+ logger . Information ( "Hello, world!" ) ;
25+ }
26+ while ( Console . ReadKey ( ) . KeyChar != 'q' ) ;
2127 }
2228 }
2329}
Original file line number Diff line number Diff line change 55using System . Runtime . CompilerServices ;
66using Microsoft . Extensions . Configuration ;
77using Microsoft . Extensions . DependencyModel ;
8+ using Microsoft . Extensions . Primitives ;
9+
810using Serilog . Configuration ;
11+ using Serilog . Core ;
12+ using Serilog . Debugging ;
913using Serilog . Events ;
1014
1115namespace Serilog . Settings . Configuration
@@ -103,7 +107,18 @@ void ApplyMinimumLevel(LoggerConfiguration loggerConfiguration)
103107 if ( ! Enum . TryParse ( minimumLevelDirective . Value , out minimumLevel ) )
104108 throw new InvalidOperationException ( $ "The value { minimumLevelDirective . Value } is not a valid Serilog level.") ;
105109
106- loggerConfiguration . MinimumLevel . Is ( minimumLevel ) ;
110+ var levelSwitch = new LoggingLevelSwitch ( minimumLevel ) ;
111+ loggerConfiguration . MinimumLevel . ControlledBy ( levelSwitch ) ;
112+
113+ ChangeToken . OnChange (
114+ ( ) => minimumLevelDirective . GetReloadToken ( ) ,
115+ ( ) =>
116+ {
117+ if ( Enum . TryParse ( minimumLevelDirective . Value , out minimumLevel ) )
118+ levelSwitch . MinimumLevel = minimumLevel ;
119+ else
120+ SelfLog . WriteLine ( $ "The value { minimumLevelDirective . Value } is not a valid Serilog level.") ;
121+ } ) ;
107122 }
108123 }
109124
You can’t perform that action at this time.
0 commit comments