@@ -170,7 +170,7 @@ public void AddSimpleConsole_ChangeProperties_IsReadFromLoggingConfiguration()
170170 var loggerProvider = new ServiceCollection ( )
171171 . AddLogging ( builder => builder
172172 . AddConfiguration ( configuration )
173- . AddSimpleConsole ( o => { } )
173+ . AddSimpleConsole ( )
174174 )
175175 . BuildServiceProvider ( )
176176 . GetRequiredService < ILoggerProvider > ( ) ;
@@ -186,6 +186,37 @@ public void AddSimpleConsole_ChangeProperties_IsReadFromLoggingConfiguration()
186186 Assert . True ( formatter . FormatterOptions . IncludeScopes ) ;
187187 }
188188
189+ [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsThreadingSupported ) ) ]
190+ [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/38337" , TestPlatforms . Browser ) ]
191+ public void AddSimpleConsole_OutsideConfig_TakesProperty ( )
192+ {
193+ var configuration = new ConfigurationBuilder ( ) . AddInMemoryCollection ( new [ ] {
194+ new KeyValuePair < string , string > ( "Console:FormatterOptions:TimestampFormat" , "HH:mm " ) ,
195+ new KeyValuePair < string , string > ( "Console:FormatterOptions:UseUtcTimestamp" , "true" ) ,
196+ new KeyValuePair < string , string > ( "Console:FormatterOptions:IncludeScopes" , "false" ) ,
197+ } ) . Build ( ) ;
198+
199+ var loggerProvider = new ServiceCollection ( )
200+ . AddLogging ( builder => builder
201+ . AddConfiguration ( configuration )
202+ . AddSimpleConsole ( o => {
203+ o . TimestampFormat = "HH:mm:ss " ;
204+ o . IncludeScopes = false ;
205+ o . UseUtcTimestamp = true ;
206+ } )
207+ )
208+ . BuildServiceProvider ( )
209+ . GetRequiredService < ILoggerProvider > ( ) ;
210+
211+ var consoleLoggerProvider = Assert . IsType < ConsoleLoggerProvider > ( loggerProvider ) ;
212+ var logger = ( ConsoleLogger ) consoleLoggerProvider . CreateLogger ( "Category" ) ;
213+ Assert . Equal ( ConsoleFormatterNames . Simple , logger . Options . FormatterName ) ;
214+ var formatter = Assert . IsType < SimpleConsoleFormatter > ( logger . Formatter ) ;
215+ Assert . Equal ( "HH:mm:ss " , formatter . FormatterOptions . TimestampFormat ) ;
216+ Assert . False ( formatter . FormatterOptions . IncludeScopes ) ;
217+ Assert . True ( formatter . FormatterOptions . UseUtcTimestamp ) ;
218+ }
219+
189220 [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsThreadingSupported ) ) ]
190221 [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/38337" , TestPlatforms . Browser ) ]
191222 public void AddSystemdConsole_ChangeProperties_IsReadFromLoggingConfiguration ( )
@@ -199,7 +230,7 @@ public void AddSystemdConsole_ChangeProperties_IsReadFromLoggingConfiguration()
199230 var loggerProvider = new ServiceCollection ( )
200231 . AddLogging ( builder => builder
201232 . AddConfiguration ( configuration )
202- . AddSystemdConsole ( o => { } )
233+ . AddSystemdConsole ( )
203234 )
204235 . BuildServiceProvider ( )
205236 . GetRequiredService < ILoggerProvider > ( ) ;
@@ -213,6 +244,37 @@ public void AddSystemdConsole_ChangeProperties_IsReadFromLoggingConfiguration()
213244 Assert . True ( formatter . FormatterOptions . IncludeScopes ) ;
214245 }
215246
247+ [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsThreadingSupported ) ) ]
248+ [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/38337" , TestPlatforms . Browser ) ]
249+ public void AddSystemdConsole_OutsideConfig_TakesProperty ( )
250+ {
251+ var configuration = new ConfigurationBuilder ( ) . AddInMemoryCollection ( new [ ] {
252+ new KeyValuePair < string , string > ( "Console:FormatterOptions:TimestampFormat" , "HH:mm " ) ,
253+ new KeyValuePair < string , string > ( "Console:FormatterOptions:UseUtcTimestamp" , "true" ) ,
254+ new KeyValuePair < string , string > ( "Console:FormatterOptions:IncludeScopes" , "true" ) ,
255+ } ) . Build ( ) ;
256+
257+ var loggerProvider = new ServiceCollection ( )
258+ . AddLogging ( builder => builder
259+ . AddConfiguration ( configuration )
260+ . AddSystemdConsole ( o => {
261+ o . TimestampFormat = "HH:mm:ss " ;
262+ o . IncludeScopes = false ;
263+ o . UseUtcTimestamp = false ;
264+ } )
265+ )
266+ . BuildServiceProvider ( )
267+ . GetRequiredService < ILoggerProvider > ( ) ;
268+
269+ var consoleLoggerProvider = Assert . IsType < ConsoleLoggerProvider > ( loggerProvider ) ;
270+ var logger = ( ConsoleLogger ) consoleLoggerProvider . CreateLogger ( "Category" ) ;
271+ Assert . Equal ( ConsoleFormatterNames . Systemd , logger . Options . FormatterName ) ;
272+ var formatter = Assert . IsType < SystemdConsoleFormatter > ( logger . Formatter ) ;
273+ Assert . Equal ( "HH:mm:ss " , formatter . FormatterOptions . TimestampFormat ) ;
274+ Assert . False ( formatter . FormatterOptions . UseUtcTimestamp ) ;
275+ Assert . False ( formatter . FormatterOptions . IncludeScopes ) ;
276+ }
277+
216278 [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsThreadingSupported ) ) ]
217279 [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/38337" , TestPlatforms . Browser ) ]
218280 public void AddJsonConsole_ChangeProperties_IsReadFromLoggingConfiguration ( )
@@ -227,7 +289,7 @@ public void AddJsonConsole_ChangeProperties_IsReadFromLoggingConfiguration()
227289 var loggerProvider = new ServiceCollection ( )
228290 . AddLogging ( builder => builder
229291 . AddConfiguration ( configuration )
230- . AddJsonConsole ( o => { } )
292+ . AddJsonConsole ( )
231293 )
232294 . BuildServiceProvider ( )
233295 . GetRequiredService < ILoggerProvider > ( ) ;
0 commit comments