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 ;
2
4
using Serilog ;
3
5
using System . IO ;
4
6
@@ -10,14 +12,18 @@ public static void Main(string[] args)
10
12
{
11
13
var configuration = new ConfigurationBuilder ( )
12
14
. SetBasePath ( Directory . GetCurrentDirectory ( ) )
13
- . AddJsonFile ( "appsettings.json" )
15
+ . AddJsonFile ( path : "appsettings.json" , optional : false , reloadOnChange : true )
14
16
. Build ( ) ;
15
17
16
18
var logger = new LoggerConfiguration ( )
17
19
. ReadFrom . Configuration ( configuration )
18
20
. CreateLogger ( ) ;
19
21
20
- logger . Information ( "Hello, world!" ) ;
22
+ do
23
+ {
24
+ logger . Information ( "Hello, world!" ) ;
25
+ }
26
+ while ( Console . ReadKey ( ) . KeyChar != 'q' ) ;
21
27
}
22
28
}
23
29
}
Original file line number Diff line number Diff line change 5
5
using System . Runtime . CompilerServices ;
6
6
using Microsoft . Extensions . Configuration ;
7
7
using Microsoft . Extensions . DependencyModel ;
8
+ using Microsoft . Extensions . Primitives ;
9
+
8
10
using Serilog . Configuration ;
11
+ using Serilog . Core ;
12
+ using Serilog . Debugging ;
9
13
using Serilog . Events ;
10
14
11
15
namespace Serilog . Settings . Configuration
@@ -103,7 +107,18 @@ void ApplyMinimumLevel(LoggerConfiguration loggerConfiguration)
103
107
if ( ! Enum . TryParse ( minimumLevelDirective . Value , out minimumLevel ) )
104
108
throw new InvalidOperationException ( $ "The value { minimumLevelDirective . Value } is not a valid Serilog level.") ;
105
109
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
+ } ) ;
107
122
}
108
123
}
109
124
You can’t perform that action at this time.
0 commit comments