5
5
6
6
namespace Sample
7
7
{
8
+ ///
9
+ /// Sample 10 false
10
+ ///
8
11
public class Program
9
12
{
10
- public static string EventCollectorToken = "1A4D65C9-601A-4717-AD6C-E1EC36A46B69 " ;
13
+ public static string EventCollectorToken = "2B94855F-1184-46F7-BFF1-56A3112F627E " ;
11
14
12
15
public static void Main ( string [ ] args )
13
16
{
14
17
var eventsToCreate = 100 ;
18
+ var runSSL = false ;
15
19
16
20
if ( args . Length > 0 )
17
21
eventsToCreate = int . Parse ( args [ 0 ] ) ;
18
22
23
+ if ( args . Length == 2 )
24
+ runSSL = bool . Parse ( args [ 1 ] ) ;
25
+
19
26
Log . Information ( "Sample starting up" ) ;
20
- Serilog . Debugging . SelfLog . Out = System . Console . Out ;
27
+ Serilog . Debugging . SelfLog . Enable ( System . Console . Out ) ;
21
28
22
- // Vanilla Tests just host
29
+ UsingHostOnly ( eventsToCreate ) ;
30
+ UsingFullUri ( eventsToCreate ) ;
31
+ OverridingSource ( eventsToCreate ) ;
32
+ OverridingSourceType ( eventsToCreate ) ;
33
+ OverridingHost ( eventsToCreate ) ;
34
+ WithNoTemplate ( eventsToCreate ) ;
35
+
36
+ if ( runSSL )
37
+ UsingSSL ( eventsToCreate ) ;
38
+
39
+ Log . Debug ( "Done" ) ;
40
+ }
41
+
42
+ public static void OverridingSource ( int eventsToCreate )
43
+ {
44
+ // Override Source
23
45
Log . Logger = new LoggerConfiguration ( )
24
46
. MinimumLevel . Debug ( )
25
47
. WriteTo . LiterateConsole ( )
26
48
. WriteTo . EventCollector (
27
- "http://localhost:8088" ,
28
- Program . EventCollectorToken )
49
+ "http://localhost:8088" ,
50
+ Program . EventCollectorToken ,
51
+ source : "Serilog.Sinks.Splunk.Sample.TestSource" )
29
52
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
30
- . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Vanilla No services/collector " )
31
- . CreateLogger ( ) ;
32
-
53
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Source Override " )
54
+ . CreateLogger ( ) ;
55
+
33
56
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
34
57
{
35
- Log . Information ( "Running vanilla without extended endpoint loop {Counter}" , i ) ;
58
+ Log . Information ( "Running source override loop {Counter}" , i ) ;
36
59
}
37
60
38
61
Log . CloseAndFlush ( ) ;
39
62
40
- // Vanilla Test with full uri specified
63
+ }
64
+
65
+ public static void OverridingSourceType ( int eventsToCreate )
66
+ {
67
+ // Override Source
41
68
Log . Logger = new LoggerConfiguration ( )
42
69
. MinimumLevel . Debug ( )
43
70
. WriteTo . LiterateConsole ( )
44
71
. WriteTo . EventCollector (
45
- "http://localhost:8088/services/collector" ,
46
- Program . EventCollectorToken )
72
+ "http://localhost:8088" ,
73
+ Program . EventCollectorToken ,
74
+ sourceType : "Serilog.Sinks.Splunk.Sample.TestSourceType" )
47
75
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
48
- . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Vanilla with full uri specified " )
49
- . CreateLogger ( ) ;
50
-
76
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Source Type Override " )
77
+ . CreateLogger ( ) ;
78
+
51
79
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
52
80
{
53
- Log . Information ( "Running vanilla loop {Counter}" , i ) ;
81
+ Log . Information ( "Running source type override loop {Counter}" , i ) ;
54
82
}
55
83
56
84
Log . CloseAndFlush ( ) ;
57
85
58
- // Override Source
86
+ }
87
+
88
+ public static void OverridingHost ( int eventsToCreate )
89
+ {
90
+ // Override Host
59
91
Log . Logger = new LoggerConfiguration ( )
60
92
. MinimumLevel . Debug ( )
61
93
. WriteTo . LiterateConsole ( )
62
94
. WriteTo . EventCollector (
63
95
"http://localhost:8088" ,
64
96
Program . EventCollectorToken ,
65
- source : "Serilog.Sinks.Splunk.Sample " )
97
+ host : "myamazingmachine " )
66
98
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
67
- . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Source Override" )
99
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Host Override" )
68
100
. CreateLogger ( ) ;
69
101
70
102
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
71
103
{
72
- Log . Information ( "Running source override loop {Counter}" , i ) ;
104
+ Log . Information ( "Running host override loop {Counter}" , i ) ;
73
105
}
74
106
75
107
Log . CloseAndFlush ( ) ;
76
-
77
- // Override Host
108
+
109
+ }
110
+
111
+ public static void UsingFullUri ( int eventsToCreate )
112
+ {
113
+ // Vanilla Test with full uri specified
78
114
Log . Logger = new LoggerConfiguration ( )
79
115
. MinimumLevel . Debug ( )
80
116
. WriteTo . LiterateConsole ( )
81
117
. WriteTo . EventCollector (
82
- "http://localhost:8088" ,
83
- Program . EventCollectorToken ,
84
- host : "myamazingmachine" )
118
+ "http://localhost:8088/services/collector" ,
119
+ Program . EventCollectorToken )
85
120
. Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
86
- . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Host Override " )
121
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Vanilla with full uri specified " )
87
122
. CreateLogger ( ) ;
88
-
123
+
124
+
89
125
foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
90
126
{
91
- Log . Information ( "Running host override loop {Counter}" , i ) ;
92
- }
127
+ Log . Information ( "Running vanilla loop with full uri {Counter}" , i ) ;
128
+ }
129
+
130
+ Log . CloseAndFlush ( ) ;
131
+ }
132
+
133
+ public static void UsingHostOnly ( int eventsToCreate )
134
+ {
135
+ // Vanilla Tests just host
136
+ Log . Logger = new LoggerConfiguration ( )
137
+ . MinimumLevel . Debug ( )
138
+ . WriteTo . LiterateConsole ( )
139
+ . WriteTo . EventCollector (
140
+ "http://localhost:8088" ,
141
+ Program . EventCollectorToken )
142
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
143
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "Vanilla No services/collector in uri" )
144
+ . CreateLogger ( ) ;
145
+
146
+ foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
147
+ {
148
+ Log . Information ( "Running vanilla without host name and port only {Counter}" , i ) ;
149
+ }
150
+
93
151
Log . CloseAndFlush ( ) ;
152
+ }
94
153
95
- // No Template
154
+ public static void WithNoTemplate ( int eventsToCreate )
155
+ {
156
+ // No Template
96
157
Log . Logger = new LoggerConfiguration ( )
97
158
. MinimumLevel . Debug ( )
98
159
. WriteTo . LiterateConsole ( )
@@ -110,26 +171,26 @@ public static void Main(string[] args)
110
171
}
111
172
112
173
Log . CloseAndFlush ( ) ;
174
+ }
113
175
114
- // // SSL
115
- // Log.Logger = new LoggerConfiguration()
116
- // .MinimumLevel.Debug()
117
- // .WriteTo.LiterateConsole()
118
- // .WriteTo.EventCollector(
119
- // "https://localhost:8088",
120
- // Program.EventCollectorToken)
121
- // .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector")
122
- // .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "HTTPS")
123
- // .CreateLogger();
176
+ public static void UsingSSL ( int eventsToCreate )
177
+ {
178
+ // SSL
179
+ Log . Logger = new LoggerConfiguration ( )
180
+ . MinimumLevel . Debug ( )
181
+ . WriteTo . LiterateConsole ( )
182
+ . WriteTo . EventCollector (
183
+ "https://localhost:8088" ,
184
+ Program . EventCollectorToken )
185
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample" , "ViaEventCollector" )
186
+ . Enrich . WithProperty ( "Serilog.Sinks.Splunk.Sample.TestType" , "HTTPS" )
187
+ . CreateLogger ( ) ;
124
188
125
- // foreach (var i in Enumerable.Range(0, eventsToCreate))
126
- // {
127
- // Log.Information("HTTPS {Counter}", i);
128
- // }
129
- // Log.CloseAndFlush();
130
-
131
- Log . Debug ( "Done" ) ;
132
-
189
+ foreach ( var i in Enumerable . Range ( 0 , eventsToCreate ) )
190
+ {
191
+ Log . Information ( "HTTPS {Counter}" , i ) ;
192
+ }
193
+ Log . CloseAndFlush ( ) ;
133
194
}
134
195
}
135
196
}
0 commit comments