Skip to content

Commit e863526

Browse files
author
Thibaud DESODT
committed
Add tests for different syntaxes of WriteTo
1 parent 815a796 commit e863526

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,37 @@ public void PropertyEnrichmentIsApplied()
4040
Assert.Equal("Test", evt.Properties["App"].LiteralValue());
4141
}
4242

43+
[Theory]
44+
[InlineData("extended syntax",
45+
@"{
46+
""Serilog"": {
47+
""Using"": [""TestDummies""],
48+
""WriteTo"": [
49+
{ ""Name"": ""DummyConsole""},
50+
{ ""Name"": ""DummyWithLevelSwitch""},
51+
]
52+
}
53+
}")]
54+
[InlineData("simplified syntax",
55+
@"{
56+
""Serilog"": {
57+
""Using"": [""TestDummies""],
58+
""WriteTo"": [""DummyConsole"", ""DummyWithLevelSwitch"" ]
59+
}
60+
}")]
61+
public void ParameterlessSinksAreConfigured(string syntax, string json)
62+
{
63+
var log = ConfigFromJson(json)
64+
.CreateLogger();
65+
66+
DummyConsoleSink.Emitted.Clear();
67+
DummyWithLevelSwitchSink.Emitted.Clear();
68+
69+
log.Write(Some.InformationEvent());
70+
71+
Assert.Equal(1, DummyConsoleSink.Emitted.Count);
72+
Assert.Equal(1, DummyWithLevelSwitchSink.Emitted.Count);
73+
}
4374

4475
[Fact]
4576
public void SinksAreConfigured()

test/TestDummies/Console/DummyConsoleSink.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Serilog.Core;
34
using Serilog.Events;
45
using TestDummies.Console.Themes;
@@ -15,8 +16,14 @@ public DummyConsoleSink(ConsoleTheme theme = null)
1516
[ThreadStatic]
1617
public static ConsoleTheme Theme;
1718

19+
[ThreadStatic]
20+
// ReSharper disable ThreadStaticFieldHasInitializer
21+
public static List<LogEvent> Emitted = new List<LogEvent>();
22+
// ReSharper restore ThreadStaticFieldHasInitializer
23+
1824
public void Emit(LogEvent logEvent)
1925
{
26+
Emitted.Add(logEvent);
2027
}
2128
}
2229

0 commit comments

Comments
 (0)