11using System . Linq ;
2- using System . Threading ;
32using Serilog ;
4- using Serilog . Core ;
3+ using Serilog . Sinks . Splunk ;
54
65namespace Sample
76{
8- ///
9- /// Sample 10 false
10- ///
117 public class Program
128 {
139 public static string EventCollectorToken = "2B94855F-1184-46F7-BFF1-56A3112F627E" ;
14-
10+
1511 public static void Main ( string [ ] args )
1612 {
1713 var eventsToCreate = 100 ;
1814 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 ] ) ;
2521
2622 Log . Information ( "Sample starting up" ) ;
2723 Serilog . Debugging . SelfLog . Enable ( System . Console . Out ) ;
@@ -32,27 +28,49 @@ public static void Main(string[] args)
3228 OverridingSourceType ( eventsToCreate ) ;
3329 OverridingHost ( eventsToCreate ) ;
3430 WithNoTemplate ( eventsToCreate ) ;
35-
36- if ( runSSL )
31+ WithCompactSplunkFormatter ( eventsToCreate ) ;
32+ if ( runSSL )
3733 UsingSSL ( eventsToCreate ) ;
38-
34+
3935 Log . Debug ( "Done" ) ;
4036 }
4137
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+
4260 public static void OverridingSource ( int eventsToCreate )
4361 {
4462 // Override Source
4563 Log . Logger = new LoggerConfiguration ( )
4664 . MinimumLevel . Debug ( )
47- . WriteTo . LiterateConsole ( )
65+ . WriteTo . LiterateConsole ( )
4866 . WriteTo . EventCollector (
49- "http://localhost:8088" ,
67+ "http://localhost:8088" ,
5068 Program . EventCollectorToken ,
5169 source : "Serilog.Sinks.Splunk.Sample.TestSource" )
5270 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
5371 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Source Override" )
5472 . CreateLogger ( ) ;
55-
73+
5674 foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
5775 {
5876 Log . Information ( "Running source override loop {Counter}" , i ) ;
@@ -67,15 +85,15 @@ public static void OverridingSourceType(int eventsToCreate)
6785 // Override Source
6886 Log . Logger = new LoggerConfiguration ( )
6987 . MinimumLevel . Debug ( )
70- . WriteTo . LiterateConsole ( )
88+ . WriteTo . LiterateConsole ( )
7189 . WriteTo . EventCollector (
72- "http://localhost:8088" ,
90+ "http://localhost:8088" ,
7391 Program . EventCollectorToken ,
7492 sourceType : "Serilog.Sinks.Splunk.Sample.TestSourceType" )
7593 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
7694 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Source Type Override" )
7795 . CreateLogger ( ) ;
78-
96+
7997 foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
8098 {
8199 Log . Information ( "Running source type override loop {Counter}" , i ) ;
@@ -90,15 +108,15 @@ public static void OverridingHost(int eventsToCreate)
90108 // Override Host
91109 Log . Logger = new LoggerConfiguration ( )
92110 . MinimumLevel . Debug ( )
93- . WriteTo . LiterateConsole ( )
111+ . WriteTo . LiterateConsole ( )
94112 . WriteTo . EventCollector (
95- "http://localhost:8088" ,
113+ "http://localhost:8088" ,
96114 Program . EventCollectorToken ,
97115 host : "myamazingmachine" )
98116 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
99117 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Host Override" )
100118 . CreateLogger ( ) ;
101-
119+
102120 foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
103121 {
104122 Log . Information ( "Running host override loop {Counter}" , i ) ;
@@ -113,7 +131,7 @@ public static void UsingFullUri(int eventsToCreate)
113131 // Vanilla Test with full uri specified
114132 Log . Logger = new LoggerConfiguration ( )
115133 . MinimumLevel . Debug ( )
116- . WriteTo . LiterateConsole ( )
134+ . WriteTo . LiterateConsole ( )
117135 . WriteTo . EventCollector (
118136 "http://localhost:8088/services/collector" ,
119137 Program . EventCollectorToken )
@@ -135,13 +153,13 @@ public static void UsingHostOnly(int eventsToCreate)
135153 // Vanilla Tests just host
136154 Log . Logger = new LoggerConfiguration ( )
137155 . MinimumLevel . Debug ( )
138- . WriteTo . LiterateConsole ( )
156+ . WriteTo . LiterateConsole ( )
139157 . WriteTo . EventCollector (
140158 "http://localhost:8088" ,
141159 Program . EventCollectorToken )
142160 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
143161 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Vanilla No services/collector in uri" )
144- . CreateLogger ( ) ;
162+ . CreateLogger ( ) ;
145163
146164 foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
147165 {
@@ -156,15 +174,15 @@ public static void WithNoTemplate(int eventsToCreate)
156174 // No Template
157175 Log . Logger = new LoggerConfiguration ( )
158176 . MinimumLevel . Debug ( )
159- . WriteTo . LiterateConsole ( )
177+ . WriteTo . LiterateConsole ( )
160178 . WriteTo . EventCollector (
161- "http://localhost:8088" ,
179+ "http://localhost:8088" ,
162180 Program . EventCollectorToken ,
163181 renderTemplate : false )
164182 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
165183 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "No Templates" )
166184 . CreateLogger ( ) ;
167-
185+
168186 foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
169187 {
170188 Log . Information ( "Running no template loop {Counter}" , i ) ;
@@ -178,14 +196,14 @@ public static void UsingSSL(int eventsToCreate)
178196 // SSL
179197 Log . Logger = new LoggerConfiguration ( )
180198 . MinimumLevel . Debug ( )
181- . WriteTo . LiterateConsole ( )
199+ . WriteTo . LiterateConsole ( )
182200 . WriteTo . EventCollector (
183201 "https://localhost:8088" ,
184202 Program . EventCollectorToken )
185203 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
186204 . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "HTTPS" )
187- . CreateLogger ( ) ;
188-
205+ . CreateLogger ( ) ;
206+
189207 foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
190208 {
191209 Log . Information ( "HTTPS {Counter}" , i ) ;
0 commit comments