@@ -200,7 +200,7 @@ protected override void Append(LoggingEvent loggingEvent)
200200 loggingEvent . EnsureNotNull ( ) ;
201201 if ( _consoleOutputWriter is not null )
202202 {
203- IntPtr consoleHandle = GetStdHandle ( _writeToErrorStream ? StdErrorHandle : StdOutputHandle ) ;
203+ IntPtr consoleHandle = NativeMethods . GetStdHandle ( _writeToErrorStream ? NativeMethods . StdErrorHandle : NativeMethods . StdOutputHandle ) ;
204204
205205 // Default to white on black
206206 ushort colorInfo = ( ushort ) Colors . White ;
@@ -215,10 +215,10 @@ protected override void Append(LoggingEvent loggingEvent)
215215 string strLoggingMessage = RenderLoggingEvent ( loggingEvent ) ;
216216
217217 // get the current console color - to restore later
218- GetConsoleScreenBufferInfo ( consoleHandle , out ConsoleScreenBufferInfo bufferInfo ) ;
218+ NativeMethods . GetConsoleScreenBufferInfo ( consoleHandle , out NativeMethods . ConsoleScreenBufferInfo bufferInfo ) ;
219219
220220 // set the console colors
221- SetConsoleTextAttribute ( consoleHandle , colorInfo ) ;
221+ NativeMethods . SetConsoleTextAttribute ( consoleHandle , colorInfo ) ;
222222
223223 // Using WriteConsoleW seems to be unreliable.
224224 // If a large buffer is written, say 15,000 chars
@@ -315,7 +315,7 @@ protected override void Append(LoggingEvent loggingEvent)
315315 _consoleOutputWriter . Write ( messageCharArray , 0 , arrayLength ) ;
316316
317317 // Restore the console back to its previous color scheme
318- SetConsoleTextAttribute ( consoleHandle , bufferInfo . wAttributes ) ;
318+ NativeMethods . SetConsoleTextAttribute ( consoleHandle , bufferInfo . wAttributes ) ;
319319
320320 if ( appendNewline )
321321 {
@@ -344,7 +344,7 @@ public override void ActivateOptions()
344344 Stream consoleOutputStream = _writeToErrorStream ? Console . OpenStandardError ( ) : Console . OpenStandardOutput ( ) ;
345345
346346 // 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 ( ) ) ) ;
348348
349349 // Create a writer around the console stream
350350 _consoleOutputWriter = new StreamWriter ( consoleOutputStream , consoleEncoding , 0x100 )
@@ -391,55 +391,6 @@ public override void ActivateOptions()
391391 /// </remarks>
392392 private StreamWriter ? _consoleOutputWriter ;
393393
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-
443394 /// <summary>
444395 /// A class to act as a mapping between the level that a logging call is made at and
445396 /// the color it should be displayed as.
0 commit comments