@@ -32,11 +32,11 @@ public ProxyTestController()
32
32
{
33
33
if ( exception is ProxyHttpException phex )
34
34
{
35
- await WriteToConsole ( exception . Message + ": " + phex . InnerException ? . Message , ConsoleColor . Red ) ;
35
+ await WriteToConsole ( exception . Message + ": " + phex . InnerException ? . Message , true ) ;
36
36
}
37
37
else
38
38
{
39
- await WriteToConsole ( exception . Message , ConsoleColor . Red ) ;
39
+ await WriteToConsole ( exception . Message , true ) ;
40
40
}
41
41
} ;
42
42
proxyServer . ForwardToUpstreamGateway = true ;
@@ -261,41 +261,24 @@ public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs
261
261
return Task . FromResult ( 0 ) ;
262
262
}
263
263
264
- private async Task WriteToConsole ( string message )
264
+ private async Task WriteToConsole ( string message , bool useRedColor = false )
265
265
{
266
266
await @lock . WaitAsync ( ) ;
267
267
268
- ConsoleColor color ;
269
-
270
- try
271
- {
272
- color = Console . ForegroundColor ;
273
- }
274
- finally
275
- {
276
- @lock . Release ( ) ;
277
- }
278
-
279
- await WriteToConsole ( message , color ) ;
280
- }
281
-
282
- private async Task WriteToConsole ( string message , ConsoleColor color )
283
- {
284
- await @lock . WaitAsync ( ) ;
285
-
286
- ConsoleColor existing = Console . ForegroundColor ;
287
-
288
- try
268
+ if ( useRedColor )
289
269
{
290
- Console . ForegroundColor = color ;
270
+ ConsoleColor existing = Console . ForegroundColor ;
271
+ Console . ForegroundColor = ConsoleColor . Red ;
291
272
Console . WriteLine ( message ) ;
273
+ Console . ForegroundColor = existing ;
292
274
}
293
- finally
275
+ else
294
276
{
295
- Console . ForegroundColor = existing ;
296
- @lock . Release ( ) ;
277
+ Console . WriteLine ( message ) ;
297
278
}
298
279
280
+ @lock . Release ( ) ;
281
+
299
282
}
300
283
301
284
///// <summary>
0 commit comments