@@ -29,15 +29,18 @@ namespace Exceptionless.SampleConsole {
29
29
public class Program {
30
30
private static readonly int [ ] _delays = { 0 , 50 , 100 , 1000 } ;
31
31
private static int _delayIndex = 2 ;
32
-
33
- private static readonly InMemoryExceptionlessLog _log = new InMemoryExceptionlessLog {
34
- MinimumLogLevel = LogLevel . Info
35
- } ;
36
-
32
+ private static readonly InMemoryExceptionlessLog _log = new InMemoryExceptionlessLog { MinimumLogLevel = LogLevel . Info } ;
37
33
private static readonly object _writeLock = new object ( ) ;
38
34
39
- private static readonly TimeSpan [ ] _dateSpans = { TimeSpan . Zero , TimeSpan . FromMinutes ( 5 ) , TimeSpan . FromHours ( 1 ) , TimeSpan . FromDays ( 1 ) , TimeSpan . FromDays ( 7 ) , TimeSpan . FromDays ( TimeSpanExtensions . AvgDaysInAMonth ) , TimeSpan . FromDays ( TimeSpanExtensions . AvgDaysInAMonth * 3 ) } ;
40
-
35
+ private static readonly TimeSpan [ ] _dateSpans = {
36
+ TimeSpan . Zero ,
37
+ TimeSpan . FromMinutes ( 5 ) ,
38
+ TimeSpan . FromHours ( 1 ) ,
39
+ TimeSpan . FromDays ( 1 ) ,
40
+ TimeSpan . FromDays ( 7 ) ,
41
+ TimeSpan . FromDays ( TimeSpanExtensions . AvgDaysInAMonth ) ,
42
+ TimeSpan . FromDays ( TimeSpanExtensions . AvgDaysInAMonth * 3 )
43
+ } ;
41
44
private static int _dateSpanIndex = 3 ;
42
45
43
46
public static void Main ( string [ ] args ) {
@@ -84,11 +87,7 @@ public static void Main(string[] args) {
84
87
ExceptionlessClient . Default . Configuration . AddPlugin ( ctx => {
85
88
// use server settings to see if we should include this data
86
89
if ( ctx . Client . Configuration . Settings . GetBoolean ( "IncludeConditionalData" , true ) )
87
- ctx . Event . AddObject ( new {
88
- Total = 32.34 ,
89
- ItemCount = 2 ,
90
-
91
- } , "ConditionalData" ) ;
90
+ ctx . Event . AddObject ( new { Total = 32.34 , ItemCount = 2 , Email = "[email protected] " } , "ConditionalData" ) ;
92
91
} ) ;
93
92
ExceptionlessClient . Default . Configuration . Settings . Changed += ( sender , changedArgs ) => Trace . WriteLine ( $ "Action: { changedArgs . Action } Key: { changedArgs . Item . Key } Value: { changedArgs . Item . Value } ") ;
94
93
@@ -110,11 +109,7 @@ public static void Main(string[] args) {
110
109
ExceptionlessClient . Default . Configuration . UseSessions ( false , null , true ) ;
111
110
ExceptionlessClient . Default . SubmitSessionStart ( ) ;
112
111
} else if ( keyInfo . Key == ConsoleKey . D6 )
113
- SendContinuousEvents ( 250 , token , ev : new Event {
114
- Type = Event . KnownTypes . Log ,
115
- Source = "SampleConsole.Program.Main" ,
116
- Message = "Sample console application event"
117
- } ) ;
112
+ SendContinuousEvents ( 250 , token , ev : new Event { Type = Event . KnownTypes . Log , Source = "SampleConsole.Program.Main" , Message = "Sample console application event" } ) ;
118
113
else if ( keyInfo . Key == ConsoleKey . D7 )
119
114
ExceptionlessClient . Default . SubmitSessionEnd ( ) ;
120
115
else if ( keyInfo . Key == ConsoleKey . D8 )
@@ -185,28 +180,13 @@ private static ConsoleKeyInfo GetKeyFromRedirectedConsole() {
185
180
}
186
181
187
182
private static void SampleApiUsages ( ) {
188
- ExceptionlessClient . Default . CreateLog ( "SampleConsole" , "Has lots of extended data" ) . AddObject ( new {
189
- myApplicationVersion = new Version ( 1 , 0 ) ,
190
- Date = DateTime . Now ,
191
- __sessionId = "9C72E4E8-20A2-469B-AFB9-492B6E349B23" ,
192
- SomeField10 = "testing"
193
- } , "Object From Code" ) . AddObject ( new {
194
- Blah = "Test"
195
- } , name : "Test Object" ) . AddObject ( "Exceptionless is awesome" , "String Content" ) . AddObject ( new int [ ] { 1 , 2 , 3 , 4 , 5 } , "Array Content" ) . AddObject ( new object [ ] { new {
196
- This = "This"
197
- } ,
198
- new {
199
- Is = "Is"
200
- } ,
201
- new {
202
- A = "A"
203
- } ,
204
- new {
205
- Test = "Test" ,
206
- Data = new {
207
- Punctuation = "!!!!"
208
- }
209
- } } , "Array With Nested Content" ) . Submit ( ) ;
183
+ ExceptionlessClient . Default . CreateLog ( "SampleConsole" , "Has lots of extended data" )
184
+ . AddObject ( new { myApplicationVersion = new Version ( 1 , 0 ) , Date = DateTime . Now , __sessionId = "9C72E4E8-20A2-469B-AFB9-492B6E349B23" , SomeField10 = "testing" } , "Object From Code" )
185
+ . AddObject ( new { Blah = "Test" } , name : "Test Object" )
186
+ . AddObject ( "Exceptionless is awesome" , "String Content" )
187
+ . AddObject ( new int [ ] { 1 , 2 , 3 , 4 , 5 } , "Array Content" )
188
+ . AddObject ( new object [ ] { new { This = "This" } , new { Is = "Is" } , new { A = "A" } , new { Test = "Test" , Data = new { Punctuation = "!!!!" } } } , "Array With Nested Content" )
189
+ . Submit ( ) ;
210
190
211
191
ExceptionlessClient . Default . SubmitFeatureUsage ( "MyFeature" ) ;
212
192
ExceptionlessClient . Default . SubmitNotFound ( "/somepage" ) ;
@@ -219,13 +199,11 @@ private static void SampleApiUsages() {
219
199
}
220
200
}
221
201
222
- private const int OPTIONS_MENU_LINE_COUNT = 14 ;
223
-
202
+ private const int OPTIONS_MENU_LINE_COUNT = 15 ;
224
203
private static void WriteOptionsMenu ( ) {
225
204
lock ( _writeLock ) {
226
205
Console . SetCursorPosition ( 0 , 0 ) ;
227
- ClearConsoleLines ( 0 , OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT ) ;
228
-
206
+ ClearConsoleLines ( 0 , OPTIONS_MENU_LINE_COUNT - 1 ) ;
229
207
Console . WriteLine ( "1: Send 1" ) ;
230
208
Console . WriteLine ( "2: Send 100" ) ;
231
209
Console . WriteLine ( "3: Send continuous" ) ;
@@ -246,19 +224,18 @@ private static void WriteOptionsMenu() {
246
224
private static void ClearOutputLines ( int delay = 1000 ) {
247
225
Task . Run ( ( ) => {
248
226
Thread . Sleep ( delay ) ;
249
- ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT ) ;
227
+ ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + 4 ) ;
250
228
} ) ;
251
229
}
252
230
253
231
private const int LOG_LINE_COUNT = 10 ;
254
-
255
232
private static void StartDisplayingLogMessages ( ) {
256
233
Task . Factory . StartNew ( async ( ) => {
257
234
while ( true ) {
258
235
var logEntries = _log . GetLogEntries ( LOG_LINE_COUNT ) ;
259
236
lock ( _writeLock ) {
260
- ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT + 4 , OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT ) ;
261
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 4 ) ;
237
+ ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT + 5 , OPTIONS_MENU_LINE_COUNT + 6 + LOG_LINE_COUNT ) ;
238
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 6 ) ;
262
239
foreach ( var logEntry in logEntries ) {
263
240
var originalColor = Console . ForegroundColor ;
264
241
Console . ForegroundColor = GetColor ( logEntry ) ;
@@ -267,7 +244,6 @@ private static void StartDisplayingLogMessages() {
267
244
}
268
245
}
269
246
270
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 1 ) ;
271
247
await Task . Delay ( 250 ) ;
272
248
}
273
249
} ) ;
@@ -305,7 +281,7 @@ private static void ClearConsoleLines(int startLine = 0, int endLine = -1) {
305
281
}
306
282
307
283
private static void SendContinuousEvents ( int delay , CancellationToken token , int maxEvents = Int32 . MaxValue , int maxDaysOld = 90 , Event ev = null ) {
308
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT ) ;
284
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
309
285
Console . WriteLine ( "Press 's' to stop sending." ) ;
310
286
int eventCount = 0 ;
311
287
@@ -322,8 +298,7 @@ private static void SendContinuousEvents(int delay, CancellationToken token, int
322
298
SendEvent ( ev , false ) ;
323
299
eventCount ++ ;
324
300
lock ( _writeLock ) {
325
- ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT + 1 , OPTIONS_MENU_LINE_COUNT + 3 ) ;
326
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
301
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 4 ) ;
327
302
Console . WriteLine ( "Submitted {0} events." , eventCount ) ;
328
303
}
329
304
@@ -335,7 +310,6 @@ private static void SendContinuousEvents(int delay, CancellationToken token, int
335
310
}
336
311
337
312
private static readonly RandomEventGenerator _rnd = new RandomEventGenerator ( ) ;
338
-
339
313
private static void SendEvent ( Event ev = null , bool writeToConsole = true ) {
340
314
_rnd . MinDate = DateTime . Now . Subtract ( _dateSpans [ _dateSpanIndex ] ) ;
341
315
_rnd . MaxDate = DateTime . Now ;
@@ -344,8 +318,7 @@ private static void SendEvent(Event ev = null, bool writeToConsole = true) {
344
318
345
319
if ( writeToConsole ) {
346
320
lock ( _writeLock ) {
347
- ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + 3 ) ;
348
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 1 ) ;
321
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
349
322
Console . WriteLine ( "Submitted 1 event." ) ;
350
323
Trace . WriteLine ( "Submitted 1 event." ) ;
351
324
}
@@ -356,8 +329,7 @@ private static void SendEvent(Event ev = null, bool writeToConsole = true) {
356
329
357
330
private static void SendAllCapturedEventsFromDisk ( ) {
358
331
lock ( _writeLock ) {
359
- ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + 3 ) ;
360
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 1 ) ;
332
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
361
333
Console . WriteLine ( "Sending captured events..." ) ;
362
334
}
363
335
@@ -373,7 +345,7 @@ private static void SendAllCapturedEventsFromDisk() {
373
345
374
346
eventCount ++ ;
375
347
lock ( _writeLock ) {
376
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
348
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 3 ) ;
377
349
Console . WriteLine ( "Sent {0} events." , eventCount ) ;
378
350
}
379
351
}
0 commit comments