@@ -8,12 +8,16 @@ namespace Serilog.Sinks.Splunk.Tests
88{
99 public class SplunkJsonFormatterTests
1010 {
11- void AssertValidJson ( Action < ILogger > act )
11+ void AssertValidJson ( Action < ILogger > act ,
12+ string source = "" ,
13+ string sourceType = "" ,
14+ string host = "" ,
15+ string index = "" )
1216 {
1317 StringWriter outputRendered = new StringWriter ( ) , output = new StringWriter ( ) ;
1418 var log = new LoggerConfiguration ( )
15- . WriteTo . Sink ( new TextWriterSink ( output , new SplunkJsonFormatter ( false , null ) ) )
16- . WriteTo . Sink ( new TextWriterSink ( outputRendered , new SplunkJsonFormatter ( true , null ) ) )
19+ . WriteTo . Sink ( new TextWriterSink ( output , new SplunkJsonFormatter ( false , null , source , sourceType , host , index ) ) )
20+ . WriteTo . Sink ( new TextWriterSink ( outputRendered , new SplunkJsonFormatter ( true , null , source , sourceType , host , index ) ) )
1721 . CreateLogger ( ) ;
1822
1923 act ( log ) ;
@@ -52,5 +56,30 @@ public void ExceptionAndPropertiesAreValidJson()
5256 {
5357 AssertValidJson ( log => log . Information ( new DivideByZeroException ( ) , "With exception and {Property}" , 42 ) ) ;
5458 }
59+
60+ [ Fact ]
61+ public void AMinimalEventWithSourceIsValidJson ( )
62+ {
63+ AssertValidJson ( log => log . Information ( "One {Property}" , 42 ) , source : "A Test Source" ) ;
64+ }
65+
66+ [ Fact ]
67+ public void AMinimalEventWithSourceTypeIsValidJson ( )
68+ {
69+ AssertValidJson ( log => log . Information ( "One {Property}" , 42 ) , sourceType : "A Test SourceType" ) ;
70+ }
71+
72+ [ Fact ]
73+ public void AMinimalEventWithHostIsValidJson ( )
74+ {
75+ AssertValidJson ( log => log . Information ( "One {Property}" , 42 ) , host : "A Test Host" ) ;
76+ }
77+
78+ [ Fact ]
79+ public void AMinimalEventWithIndexIsValidJson ( )
80+ {
81+ AssertValidJson ( log => log . Information ( "One {Property}" , 42 ) , host : "testindex" ) ;
82+ }
83+
5584 }
56- }
85+ }
0 commit comments