@@ -35,7 +35,8 @@ public class Program {
35
35
36
36
public static void Main ( string [ ] args ) {
37
37
Console . CursorVisible = false ;
38
- StartDisplayingLogMessages ( ) ;
38
+ if ( ! Console . IsInputRedirected )
39
+ StartDisplayingLogMessages ( ) ;
39
40
40
41
ExceptionlessClient . Default . Configuration . UpdateSettingsWhenIdleInterval = TimeSpan . FromSeconds ( 15 ) ;
41
42
ExceptionlessClient . Default . Configuration . UseTraceLogEntriesPlugin ( ) ;
@@ -49,7 +50,7 @@ public static void Main(string[] args) {
49
50
GlobalDiagnosticsContext . Set ( "GlobalProp" , "GlobalValue" ) ;
50
51
//Log.Info().Message("Hi").Tag("Tag1", "Tag2").Property("LocalProp", "LocalValue").MarkUnhandled("SomeMethod").ContextProperty("Blah", new Event()).Write();
51
52
52
- //ExceptionlessClient.Default.SubmitLog(typeof(Program).Name, "Trace Message", LogLevel.Trace);
53
+ //ExceptionlessClient.Default.SubmitLog(typeof(Program).Name, "Trace Message", LogLevel.Trace);
53
54
54
55
#if NET45
55
56
// test log4net
@@ -79,7 +80,7 @@ public static void Main(string[] args) {
79
80
80
81
while ( true ) {
81
82
Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 1 ) ;
82
- ConsoleKeyInfo keyInfo = Console . ReadKey ( true ) ;
83
+ var keyInfo = Console . IsInputRedirected ? GetKeyFromRedirectedConsole ( ) : Console . ReadKey ( true ) ;
83
84
84
85
if ( keyInfo . Key == ConsoleKey . D1 )
85
86
SendEvent ( ) ;
@@ -133,6 +134,40 @@ public static void Main(string[] args) {
133
134
}
134
135
}
135
136
137
+ private static ConsoleKeyInfo GetKeyFromRedirectedConsole ( ) {
138
+ string input = Console . In . ReadLine ( ) ;
139
+ switch ( input ? . ToLower ( ) ) {
140
+ case "1" :
141
+ return new ConsoleKeyInfo ( '1' , ConsoleKey . D1 , false , false , false ) ;
142
+ case "2" :
143
+ return new ConsoleKeyInfo ( '2' , ConsoleKey . D2 , false , false , false ) ;
144
+ case "3" :
145
+ return new ConsoleKeyInfo ( '3' , ConsoleKey . D3 , false , false , false ) ;
146
+ case "4" :
147
+ return new ConsoleKeyInfo ( '4' , ConsoleKey . D4 , false , false , false ) ;
148
+ case "5" :
149
+ return new ConsoleKeyInfo ( '5' , ConsoleKey . D5 , false , false , false ) ;
150
+ case "6" :
151
+ return new ConsoleKeyInfo ( '6' , ConsoleKey . D6 , false , false , false ) ;
152
+ case "7" :
153
+ return new ConsoleKeyInfo ( '7' , ConsoleKey . D7 , false , false , false ) ;
154
+ case "8" :
155
+ return new ConsoleKeyInfo ( '8' , ConsoleKey . D8 , false , false , false ) ;
156
+ case "p" :
157
+ return new ConsoleKeyInfo ( 'p' , ConsoleKey . P , false , false , false ) ;
158
+ case "f" :
159
+ return new ConsoleKeyInfo ( 'f' , ConsoleKey . F , false , false , false ) ;
160
+ case "d" :
161
+ return new ConsoleKeyInfo ( 'd' , ConsoleKey . D , false , false , false ) ;
162
+ case "t" :
163
+ return new ConsoleKeyInfo ( 't' , ConsoleKey . T , false , false , false ) ;
164
+ case "q" :
165
+ return new ConsoleKeyInfo ( 'q' , ConsoleKey . Q , false , false , false ) ;
166
+ }
167
+
168
+ return new ConsoleKeyInfo ( ' ' , ConsoleKey . Escape , false , false , false ) ;
169
+ }
170
+
136
171
private static void SampleApiUsages ( ) {
137
172
ExceptionlessClient . Default . CreateLog ( "SampleConsole" , "Has lots of extended data" ) . AddObject ( new {
138
173
myApplicationVersion = new Version ( 1 , 0 ) ,
@@ -168,12 +203,13 @@ private static void SampleApiUsages() {
168
203
}
169
204
}
170
205
171
- private const int OPTIONS_MENU_LINE_COUNT = 15 ;
206
+ private const int OPTIONS_MENU_LINE_COUNT = 14 ;
172
207
173
208
private static void WriteOptionsMenu ( ) {
174
209
lock ( _writeLock ) {
175
210
Console . SetCursorPosition ( 0 , 0 ) ;
176
- ClearConsoleLines ( 0 , OPTIONS_MENU_LINE_COUNT - 1 ) ;
211
+ ClearConsoleLines ( 0 , OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT ) ;
212
+
177
213
Console . WriteLine ( "1: Send 1" ) ;
178
214
Console . WriteLine ( "2: Send 100" ) ;
179
215
Console . WriteLine ( "3: Send continuous" ) ;
@@ -194,27 +230,29 @@ private static void WriteOptionsMenu() {
194
230
private static void ClearOutputLines ( int delay = 1000 ) {
195
231
Task . Run ( ( ) => {
196
232
Thread . Sleep ( delay ) ;
197
- ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + 4 ) ;
233
+ ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT ) ;
198
234
} ) ;
199
235
}
200
236
201
237
private const int LOG_LINE_COUNT = 10 ;
202
238
203
239
private static void StartDisplayingLogMessages ( ) {
204
- Task . Factory . StartNew ( ( ) => {
240
+ Task . Factory . StartNew ( async ( ) => {
205
241
while ( true ) {
206
242
var logEntries = _log . GetLogEntries ( LOG_LINE_COUNT ) ;
207
243
lock ( _writeLock ) {
208
- ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT + 5 , OPTIONS_MENU_LINE_COUNT + 6 + LOG_LINE_COUNT ) ;
209
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 6 ) ;
244
+ ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT + 4 , OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT ) ;
245
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 4 ) ;
210
246
foreach ( var logEntry in logEntries ) {
211
247
var originalColor = Console . ForegroundColor ;
212
248
Console . ForegroundColor = GetColor ( logEntry ) ;
213
249
Console . WriteLine ( logEntry ) ;
214
250
Console . ForegroundColor = originalColor ;
215
251
}
216
252
}
217
- Thread . Sleep ( 250 ) ;
253
+
254
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 1 ) ;
255
+ await Task . Delay ( 250 ) ;
218
256
}
219
257
} ) ;
220
258
}
@@ -268,7 +306,8 @@ private static void SendContinuousEvents(int delay, CancellationToken token, int
268
306
SendEvent ( ev , false ) ;
269
307
eventCount ++ ;
270
308
lock ( _writeLock ) {
271
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 4 ) ;
309
+ ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + 3 ) ;
310
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
272
311
Console . WriteLine ( "Submitted {0} events." , eventCount ) ;
273
312
}
274
313
@@ -289,7 +328,8 @@ private static void SendEvent(Event ev = null, bool writeToConsole = true) {
289
328
290
329
if ( writeToConsole ) {
291
330
lock ( _writeLock ) {
292
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
331
+ ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + 3 ) ;
332
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 1 ) ;
293
333
Console . WriteLine ( "Submitted 1 event." ) ;
294
334
Trace . WriteLine ( "Submitted 1 event." ) ;
295
335
}
@@ -300,7 +340,8 @@ private static void SendEvent(Event ev = null, bool writeToConsole = true) {
300
340
301
341
private static void SendAllCapturedEventsFromDisk ( ) {
302
342
lock ( _writeLock ) {
303
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
343
+ ClearConsoleLines ( OPTIONS_MENU_LINE_COUNT , OPTIONS_MENU_LINE_COUNT + 3 ) ;
344
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 1 ) ;
304
345
Console . WriteLine ( "Sending captured events..." ) ;
305
346
}
306
347
@@ -316,7 +357,7 @@ private static void SendAllCapturedEventsFromDisk() {
316
357
317
358
eventCount ++ ;
318
359
lock ( _writeLock ) {
319
- Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 3 ) ;
360
+ Console . SetCursorPosition ( 0 , OPTIONS_MENU_LINE_COUNT + 2 ) ;
320
361
Console . WriteLine ( "Sent {0} events." , eventCount ) ;
321
362
}
322
363
}
0 commit comments