@@ -12,9 +12,12 @@ 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 )
19
+ builder . AddJsonString ( secondJsonSource ) ;
20
+ var config = builder . Build ( ) ;
18
21
return new LoggerConfiguration ( )
19
22
. ReadFrom . Configuration ( config ) ;
20
23
}
@@ -31,7 +34,7 @@ public void PropertyEnrichmentIsApplied()
31
34
}
32
35
}
33
36
}" ;
34
-
37
+
35
38
var log = ConfigFromJson ( json )
36
39
. WriteTo . Sink ( new DelegatingSink ( e => evt = e ) )
37
40
. CreateLogger ( ) ;
@@ -114,7 +117,7 @@ public void AuditSinksAreConfigured()
114
117
115
118
var log = ConfigFromJson ( json )
116
119
. CreateLogger ( ) ;
117
-
120
+
118
121
DummyRollingFileSink . Emitted . Clear ( ) ;
119
122
DummyRollingFileAuditSink . Emitted . Clear ( ) ;
120
123
@@ -227,7 +230,7 @@ public void LoggingLevelSwitchWithInvalidNameThrowsFormatException()
227
230
""LevelSwitches"": {""switchNameNotStartingWithDollar"" : ""Warning"" }
228
231
}
229
232
}" ;
230
-
233
+
231
234
var ex = Assert . Throws < FormatException > ( ( ) => ConfigFromJson ( json ) ) ;
232
235
233
236
Assert . Contains ( "\" switchNameNotStartingWithDollar\" " , ex . Message ) ;
@@ -271,7 +274,7 @@ public void SettingMinimumLevelControlledByToAnUndeclaredSwitchThrows()
271
274
}
272
275
}
273
276
}" ;
274
-
277
+
275
278
var ex = Assert . Throws < InvalidOperationException > ( ( ) =>
276
279
ConfigFromJson ( json )
277
280
. CreateLogger ( ) ) ;
@@ -332,7 +335,7 @@ public void ReferencingAnUndeclaredSwitchInSinkThrows()
332
335
}]
333
336
}
334
337
}" ;
335
-
338
+
336
339
var ex = Assert . Throws < InvalidOperationException > ( ( ) =>
337
340
ConfigFromJson ( json )
338
341
. CreateLogger ( ) ) ;
@@ -544,8 +547,8 @@ public void WriteToSubLoggerWithLevelSwitchIsSupported()
544
547
}
545
548
}]
546
549
}
547
- }" ;
548
-
550
+ }" ;
551
+
549
552
var log = ConfigFromJson ( json )
550
553
. CreateLogger ( ) ;
551
554
@@ -556,5 +559,43 @@ public void WriteToSubLoggerWithLevelSwitchIsSupported()
556
559
557
560
Assert . Equal ( 1 , DummyRollingFileSink . Emitted . Count ) ;
558
561
}
562
+
563
+ [ Trait ( "Bugfix" , "#103" ) ]
564
+ [ Fact ]
565
+ public void InconsistentComplexVsScalarArgumentValuesThrowsIOE ( )
566
+ {
567
+ var jsonDiscreteValue = @"{
568
+ ""Serilog"": {
569
+ ""Using"": [""TestDummies""],
570
+ ""WriteTo"": [{
571
+ ""Name"": ""DummyRollingFile"",
572
+ ""Args"": {""pathFormat"" : ""C:\\""}
573
+ }]
574
+ }
575
+ }" ;
576
+
577
+ var jsonComplexValue = @"{
578
+ ""Serilog"": {
579
+ ""Using"": [""TestDummies""],
580
+ ""WriteTo"": [{
581
+ ""Name"": ""DummyRollingFile"",
582
+ ""Args"": {""pathFormat"" : { ""foo"" : ""bar"" } }
583
+ }]
584
+ }
585
+ }" ;
586
+
587
+ // These will combine into a ConfigurationSection object that has both
588
+ // Value == "C:\" and GetChildren() == List<string>. No configuration
589
+ // extension matching this exists (in theory an "object" argument could
590
+ // accept either value). ConfigurationReader should throw as soon as
591
+ // the multiple values are recognized; it will never attempt to locate
592
+ // a matching argument.
593
+
594
+ var ex = Assert . Throws < InvalidOperationException > ( ( )
595
+ => ConfigFromJson ( jsonDiscreteValue , jsonComplexValue ) ) ;
596
+
597
+ Assert . Contains ( "The value for the argument" , ex . Message ) ;
598
+ Assert . Contains ( "'Serilog:WriteTo:0:Args:pathFormat'" , ex . Message ) ;
599
+ }
559
600
}
560
601
}
0 commit comments