@@ -200,7 +200,7 @@ protected override void Append(LoggingEvent loggingEvent)
200
200
loggingEvent . EnsureNotNull ( ) ;
201
201
if ( _consoleOutputWriter is not null )
202
202
{
203
- IntPtr consoleHandle = GetStdHandle ( _writeToErrorStream ? StdErrorHandle : StdOutputHandle ) ;
203
+ IntPtr consoleHandle = NativeMethods . GetStdHandle ( _writeToErrorStream ? NativeMethods . StdErrorHandle : NativeMethods . StdOutputHandle ) ;
204
204
205
205
// Default to white on black
206
206
ushort colorInfo = ( ushort ) Colors . White ;
@@ -215,10 +215,10 @@ protected override void Append(LoggingEvent loggingEvent)
215
215
string strLoggingMessage = RenderLoggingEvent ( loggingEvent ) ;
216
216
217
217
// get the current console color - to restore later
218
- GetConsoleScreenBufferInfo ( consoleHandle , out ConsoleScreenBufferInfo bufferInfo ) ;
218
+ NativeMethods . GetConsoleScreenBufferInfo ( consoleHandle , out NativeMethods . ConsoleScreenBufferInfo bufferInfo ) ;
219
219
220
220
// set the console colors
221
- SetConsoleTextAttribute ( consoleHandle , colorInfo ) ;
221
+ NativeMethods . SetConsoleTextAttribute ( consoleHandle , colorInfo ) ;
222
222
223
223
// Using WriteConsoleW seems to be unreliable.
224
224
// If a large buffer is written, say 15,000 chars
@@ -315,7 +315,7 @@ protected override void Append(LoggingEvent loggingEvent)
315
315
_consoleOutputWriter . Write ( messageCharArray , 0 , arrayLength ) ;
316
316
317
317
// Restore the console back to its previous color scheme
318
- SetConsoleTextAttribute ( consoleHandle , bufferInfo . wAttributes ) ;
318
+ NativeMethods . SetConsoleTextAttribute ( consoleHandle , bufferInfo . wAttributes ) ;
319
319
320
320
if ( appendNewline )
321
321
{
@@ -344,7 +344,7 @@ public override void ActivateOptions()
344
344
Stream consoleOutputStream = _writeToErrorStream ? Console . OpenStandardError ( ) : Console . OpenStandardOutput ( ) ;
345
345
346
346
// Look up the codepage encoding for the console
347
- Encoding consoleEncoding = EncodingWithoutPreamble . Get ( Encoding . GetEncoding ( GetConsoleOutputCP ( ) ) ) ;
347
+ Encoding consoleEncoding = EncodingWithoutPreamble . Get ( Encoding . GetEncoding ( NativeMethods . GetConsoleOutputCP ( ) ) ) ;
348
348
349
349
// Create a writer around the console stream
350
350
_consoleOutputWriter = new StreamWriter ( consoleOutputStream , consoleEncoding , 0x100 )
@@ -391,55 +391,6 @@ public override void ActivateOptions()
391
391
/// </remarks>
392
392
private StreamWriter ? _consoleOutputWriter ;
393
393
394
- [ DllImport ( "Kernel32.dll" , SetLastError = true , CharSet = CharSet . Auto ) ]
395
- [ DefaultDllImportSearchPaths ( DllImportSearchPath . System32 ) ]
396
- private static extern int GetConsoleOutputCP ( ) ;
397
-
398
- [ DllImport ( "Kernel32.dll" , SetLastError = true , CharSet = CharSet . Auto ) ]
399
- [ DefaultDllImportSearchPaths ( DllImportSearchPath . System32 ) ]
400
- private static extern bool SetConsoleTextAttribute (
401
- IntPtr consoleHandle ,
402
- ushort attributes ) ;
403
-
404
- [ DllImport ( "Kernel32.dll" , SetLastError = true , CharSet = CharSet . Auto ) ]
405
- [ DefaultDllImportSearchPaths ( DllImportSearchPath . System32 ) ]
406
- private static extern bool GetConsoleScreenBufferInfo (
407
- IntPtr consoleHandle ,
408
- out ConsoleScreenBufferInfo bufferInfo ) ;
409
-
410
- private const uint StdOutputHandle = unchecked ( ( uint ) - 11 ) ;
411
- private const uint StdErrorHandle = unchecked ( ( uint ) - 12 ) ;
412
-
413
- [ DllImport ( "Kernel32.dll" , SetLastError = true , CharSet = CharSet . Auto ) ]
414
- [ DefaultDllImportSearchPaths ( DllImportSearchPath . System32 ) ]
415
- private static extern IntPtr GetStdHandle ( uint type ) ;
416
-
417
- [ StructLayout ( LayoutKind . Sequential ) ]
418
- private struct Coord
419
- {
420
- public ushort x ;
421
- public ushort y ;
422
- }
423
-
424
- [ StructLayout ( LayoutKind . Sequential ) ]
425
- private struct SmallRect
426
- {
427
- public ushort Left ;
428
- public ushort Top ;
429
- public ushort Right ;
430
- public ushort Bottom ;
431
- }
432
-
433
- [ StructLayout ( LayoutKind . Sequential ) ]
434
- private struct ConsoleScreenBufferInfo
435
- {
436
- public Coord dwSize ;
437
- public Coord dwCursorPosition ;
438
- public ushort wAttributes ;
439
- public SmallRect srWindow ;
440
- public Coord dwMaximumWindowSize ;
441
- }
442
-
443
394
/// <summary>
444
395
/// A class to act as a mapping between the level that a logging call is made at and
445
396
/// the color it should be displayed as.
0 commit comments