1
1
using System . Linq ;
2
- using System . Threading ;
3
2
using Serilog ;
4
- using Serilog . Core ;
3
+ using Serilog . Sinks . Splunk ;
5
4
6
5
namespace Sample
7
6
{
8
- ///
9
- /// Sample 10 false
10
- ///
11
7
public class Program
12
8
{
13
9
public static string EventCollectorToken = "2B94855F-1184-46F7-BFF1-56A3112F627E" ;
14
-
10
+
15
11
public static void Main ( string [ ] args )
16
12
{
17
13
var eventsToCreate = 100 ;
18
14
var runSSL = false ;
19
-
20
- if ( args . Length > 0 )
21
- eventsToCreate = int . Parse ( args [ 0 ] ) ;
22
-
23
- if ( args . Length == 2 )
24
- runSSL = bool . Parse ( args [ 1 ] ) ;
15
+
16
+ if ( args . Length > 0 )
17
+ eventsToCreate = int . Parse ( args [ 0 ] ) ;
18
+
19
+ if ( args . Length == 2 )
20
+ runSSL = bool . Parse ( args [ 1 ] ) ;
25
21
26
22
Log . Information ( "Sample starting up" ) ;
27
23
Serilog . Debugging . SelfLog . Enable ( System . Console . Out ) ;
@@ -32,27 +28,49 @@ public static void Main(string[] args)
32
28
OverridingSourceType ( eventsToCreate ) ;
33
29
OverridingHost ( eventsToCreate ) ;
34
30
WithNoTemplate ( eventsToCreate ) ;
35
-
36
- if ( runSSL )
31
+ WithCompactSplunkFormatter ( eventsToCreate ) ;
32
+ if ( runSSL )
37
33
UsingSSL ( eventsToCreate ) ;
38
-
34
+
39
35
Log . Debug ( "Done" ) ;
40
36
}
41
37
38
+ private static void WithCompactSplunkFormatter ( int eventsToCreate )
39
+ {
40
+ // Vanilla Test with full uri specified
41
+ Log . Logger = new LoggerConfiguration ( )
42
+ . MinimumLevel . Debug ( )
43
+ . WriteTo . LiterateConsole ( )
44
+ . WriteTo . EventCollector (
45
+ "http://localhost:8088/services/collector" ,
46
+ Program . EventCollectorToken , new CompactSplunkJsonFormatter ( ) )
47
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
48
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Vanilla with CompactSplunkJsonFormatter specified" )
49
+ . CreateLogger ( ) ;
50
+
51
+
52
+ foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
53
+ {
54
+ Log . Information ( "{Counter}{Message}" , i , "Running vanilla loop with CompactSplunkJsonFormatter" ) ;
55
+ }
56
+
57
+ Log . CloseAndFlush ( ) ;
58
+ }
59
+
42
60
public static void OverridingSource ( int eventsToCreate )
43
61
{
44
62
// Override Source
45
63
Log . Logger = new LoggerConfiguration ( )
46
64
. MinimumLevel . Debug ( )
47
- . WriteTo . LiterateConsole ( )
65
+ . WriteTo . LiterateConsole ( )
48
66
. WriteTo . EventCollector (
49
- "http://localhost:8088" ,
67
+ "http://localhost:8088" ,
50
68
Program . EventCollectorToken ,
51
69
source : "Serilog.Sinks.Splunk.Sample.TestSource" )
52
70
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
53
71
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Source Override" )
54
72
. CreateLogger ( ) ;
55
-
73
+
56
74
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
57
75
{
58
76
Log . Information ( "Running source override loop {Counter}" , i ) ;
@@ -67,15 +85,15 @@ public static void OverridingSourceType(int eventsToCreate)
67
85
// Override Source
68
86
Log . Logger = new LoggerConfiguration ( )
69
87
. MinimumLevel . Debug ( )
70
- . WriteTo . LiterateConsole ( )
88
+ . WriteTo . LiterateConsole ( )
71
89
. WriteTo . EventCollector (
72
- "http://localhost:8088" ,
90
+ "http://localhost:8088" ,
73
91
Program . EventCollectorToken ,
74
92
sourceType : "Serilog.Sinks.Splunk.Sample.TestSourceType" )
75
93
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
76
94
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Source Type Override" )
77
95
. CreateLogger ( ) ;
78
-
96
+
79
97
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
80
98
{
81
99
Log . Information ( "Running source type override loop {Counter}" , i ) ;
@@ -90,15 +108,15 @@ public static void OverridingHost(int eventsToCreate)
90
108
// Override Host
91
109
Log . Logger = new LoggerConfiguration ( )
92
110
. MinimumLevel . Debug ( )
93
- . WriteTo . LiterateConsole ( )
111
+ . WriteTo . LiterateConsole ( )
94
112
. WriteTo . EventCollector (
95
- "http://localhost:8088" ,
113
+ "http://localhost:8088" ,
96
114
Program . EventCollectorToken ,
97
115
host : "myamazingmachine" )
98
116
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
99
117
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Host Override" )
100
118
. CreateLogger ( ) ;
101
-
119
+
102
120
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
103
121
{
104
122
Log . Information ( "Running host override loop {Counter}" , i ) ;
@@ -113,7 +131,7 @@ public static void UsingFullUri(int eventsToCreate)
113
131
// Vanilla Test with full uri specified
114
132
Log . Logger = new LoggerConfiguration ( )
115
133
. MinimumLevel . Debug ( )
116
- . WriteTo . LiterateConsole ( )
134
+ . WriteTo . LiterateConsole ( )
117
135
. WriteTo . EventCollector (
118
136
"http://localhost:8088/services/collector" ,
119
137
Program . EventCollectorToken )
@@ -135,13 +153,13 @@ public static void UsingHostOnly(int eventsToCreate)
135
153
// Vanilla Tests just host
136
154
Log . Logger = new LoggerConfiguration ( )
137
155
. MinimumLevel . Debug ( )
138
- . WriteTo . LiterateConsole ( )
156
+ . WriteTo . LiterateConsole ( )
139
157
. WriteTo . EventCollector (
140
158
"http://localhost:8088" ,
141
159
Program . EventCollectorToken )
142
160
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
143
161
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Vanilla No services/collector in uri" )
144
- . CreateLogger ( ) ;
162
+ . CreateLogger ( ) ;
145
163
146
164
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
147
165
{
@@ -156,15 +174,15 @@ public static void WithNoTemplate(int eventsToCreate)
156
174
// No Template
157
175
Log . Logger = new LoggerConfiguration ( )
158
176
. MinimumLevel . Debug ( )
159
- . WriteTo . LiterateConsole ( )
177
+ . WriteTo . LiterateConsole ( )
160
178
. WriteTo . EventCollector (
161
- "http://localhost:8088" ,
179
+ "http://localhost:8088" ,
162
180
Program . EventCollectorToken ,
163
181
renderTemplate : false )
164
182
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
165
183
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "No Templates" )
166
184
. CreateLogger ( ) ;
167
-
185
+
168
186
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
169
187
{
170
188
Log . Information ( "Running no template loop {Counter}" , i ) ;
@@ -178,14 +196,14 @@ public static void UsingSSL(int eventsToCreate)
178
196
// SSL
179
197
Log . Logger = new LoggerConfiguration ( )
180
198
. MinimumLevel . Debug ( )
181
- . WriteTo . LiterateConsole ( )
199
+ . WriteTo . LiterateConsole ( )
182
200
. WriteTo . EventCollector (
183
201
"https://localhost:8088" ,
184
202
Program . EventCollectorToken )
185
203
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
186
204
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "HTTPS" )
187
- . CreateLogger ( ) ;
188
-
205
+ . CreateLogger ( ) ;
206
+
189
207
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
190
208
{
191
209
Log . Information ( "HTTPS {Counter}" , i ) ;
0 commit comments