@@ -12,9 +12,11 @@ namespace Serilog.Settings.Configuration.Tests
12
12
{
13
13
public class ConfigurationSettingsTests
14
14
{
15
- static LoggerConfiguration ConfigFromJson ( string jsonString )
15
+ static LoggerConfiguration ConfigFromJson ( string jsonString , string secondJsonSource = null )
16
16
{
17
- var config = new ConfigurationBuilder ( ) . AddJsonString ( jsonString ) . Build ( ) ;
17
+ var builder = new ConfigurationBuilder ( ) . AddJsonString ( jsonString ) ;
18
+ if ( secondJsonSource != null ) builder . AddJsonString ( secondJsonSource ) ;
19
+ var config = builder . Build ( ) ;
18
20
return new LoggerConfiguration ( )
19
21
. ReadFrom . Configuration ( config ) ;
20
22
}
@@ -556,5 +558,42 @@ public void WriteToSubLoggerWithLevelSwitchIsSupported()
556
558
557
559
Assert . Equal ( 1 , DummyRollingFileSink . Emitted . Count ) ;
558
560
}
561
+
562
+ [ Trait ( "Bugfix" , "#103" ) ]
563
+ [ Fact ]
564
+ public void MultipleArgumentValuesThrowsInvalidOperationException ( )
565
+ {
566
+ var jsonDiscreteValue = @"{
567
+ ""Serilog"": {
568
+ ""Using"": [""TestDummies""],
569
+ ""WriteTo"": [{
570
+ ""Name"": ""DummyRollingFile"",
571
+ ""Args"": {""pathFormat"" : ""C:\\""}
572
+ }]
573
+ }
574
+ }" ;
575
+
576
+ var jsonComplexValue = @"{
577
+ ""Serilog"": {
578
+ ""Using"": [""TestDummies""],
579
+ ""WriteTo"": [{
580
+ ""Name"": ""DummyRollingFile"",
581
+ ""Args"": {""pathFormat"" : { ""foo"" : ""bar"" } }
582
+ }]
583
+ }
584
+ }" ;
585
+
586
+ // These will combine into a ConfigurationSection object that has both
587
+ // Value == "C:\" and GetChildren() == List<string>. No configuration
588
+ // extension matching this exists (in theory an "object" argument could
589
+ // accept either value). ConfigurationReader should throw as soon as
590
+ // the multiple values are recognized; it will never attempt to locate
591
+ // a matching argument.
592
+
593
+ var ex = Assert . Throws < InvalidOperationException > ( ( ) => ConfigFromJson ( jsonDiscreteValue , jsonComplexValue ) ) ;
594
+
595
+ Assert . Contains ( "Combined configuration sources" , ex . Message ) ;
596
+ Assert . Contains ( "pathFormat" , ex . Message ) ;
597
+ }
559
598
}
560
599
}
0 commit comments