@@ -419,32 +419,76 @@ public void LoggingLevelSwitchCanBeUsedForMinimumLevelOverrides()
419
419
}
420
420
421
421
[ Fact ]
422
+
423
+ [ Trait ( "BugFix" , "https://github.com/serilog/serilog-settings-configuration/issues/142" ) ]
422
424
public void SinkWithIConfigurationArguments ( )
423
425
{
424
426
var json = @"{
425
427
""Serilog"": {
426
428
""Using"": [""TestDummies""],
427
429
""WriteTo"": [{
428
- ""Name"": ""DummyRollingFile"",
429
- ""Args"": {""pathFormat"" : ""C:\\"",
430
- ""configurationSection"" : { ""foo"" : ""bar"" } }
430
+ ""Name"": ""DummyWithConfiguration"",
431
+ ""Args"": {}
431
432
}]
432
433
}
433
434
}" ;
434
435
435
- // IConfiguration and IConfigurationSection arguments do not have
436
- // default values so they will throw if they are not populated
437
-
436
+ DummyConfigurationSink . Reset ( ) ;
438
437
var log = ConfigFromJson ( json )
439
438
. CreateLogger ( ) ;
440
439
441
- DummyRollingFileSink . Reset ( ) ;
440
+ log . Write ( Some . InformationEvent ( ) ) ;
441
+
442
+ Assert . NotNull ( DummyConfigurationSink . Configuration ) ;
443
+ }
444
+
445
+ [ Fact ]
446
+ [ Trait ( "BugFix" , "https://github.com/serilog/serilog-settings-configuration/issues/142" ) ]
447
+ public void SinkWithOptionalIConfigurationArguments ( )
448
+ {
449
+ var json = @"{
450
+ ""Serilog"": {
451
+ ""Using"": [""TestDummies""],
452
+ ""WriteTo"": [{
453
+ ""Name"": ""DummyWithOptionalConfiguration"",
454
+ ""Args"": {}
455
+ }]
456
+ }
457
+ }" ;
458
+
459
+ DummyConfigurationSink . Reset ( ) ;
460
+ var log = ConfigFromJson ( json )
461
+ . CreateLogger ( ) ;
442
462
443
463
log . Write ( Some . InformationEvent ( ) ) ;
444
464
445
- Assert . Equal ( 1 , DummyRollingFileSink . Emitted . Count ) ;
465
+ Assert . NotNull ( DummyConfigurationSink . Configuration ) ;
466
+ }
467
+
468
+ [ Fact ]
469
+ public void SinkWithIConfigSectionArguments ( )
470
+ {
471
+ var json = @"{
472
+ ""Serilog"": {
473
+ ""Using"": [""TestDummies""],
474
+ ""WriteTo"": [{
475
+ ""Name"": ""DummyWithConfigSection"",
476
+ ""Args"": {""configurationSection"" : { ""foo"" : ""bar"" } }
477
+ }]
478
+ }
479
+ }" ;
480
+
481
+ DummyConfigurationSink . Reset ( ) ;
482
+ var log = ConfigFromJson ( json )
483
+ . CreateLogger ( ) ;
484
+
485
+ log . Write ( Some . InformationEvent ( ) ) ;
486
+
487
+ Assert . NotNull ( DummyConfigurationSink . ConfigSection ) ;
488
+ Assert . Equal ( "bar" , DummyConfigurationSink . ConfigSection [ "foo" ] ) ;
446
489
}
447
490
491
+
448
492
[ Fact ]
449
493
public void SinkWithConfigurationBindingArgument ( )
450
494
{
0 commit comments