@@ -8,12 +8,16 @@ namespace Serilog.Sinks.Splunk.Tests
8
8
{
9
9
public class SplunkJsonFormatterTests
10
10
{
11
- void AssertValidJson ( Action < ILogger > act )
11
+ void AssertValidJson ( Action < ILogger > act ,
12
+ string source = "" ,
13
+ string sourceType = "" ,
14
+ string host = "" ,
15
+ string index = "" )
12
16
{
13
17
StringWriter outputRendered = new StringWriter ( ) , output = new StringWriter ( ) ;
14
18
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 ) ) )
17
21
. CreateLogger ( ) ;
18
22
19
23
act ( log ) ;
@@ -52,5 +56,30 @@ public void ExceptionAndPropertiesAreValidJson()
52
56
{
53
57
AssertValidJson ( log => log . Information ( new DivideByZeroException ( ) , "With exception and {Property}" , 42 ) ) ;
54
58
}
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
+
55
84
}
56
- }
85
+ }
0 commit comments