[prev in list] [next in list] [prev in thread] [next in thread]
List: log4net-dev
Subject: RE: Make ColoredConsoleAppender reset console's colors when finished.
From: "Nicko Cadell" <nicko () neoworks ! com>
Date: 2005-01-28 22:40:09
Message-ID: DDEB64C8619AC64DBC074208B046611C59C8D8 () kronos ! neoworks ! co ! uk
[Download RAW message or body]
An equivalent patch has already been applied to CVS to fix this issue.
Many thanks,
Nicko
> -----Original Message-----
> From: Wesley Smith [mailto:WesleyS@tdsway.com]
> Sent: 27 January 2005 20:10
> To: log4net-dev@logging.apache.org
> Subject: Make ColoredConsoleAppender reset console's colors
> when finished.
>
> ColoredConsoleAppender does not reset the console's colors
> back to their original color, so that after the program being
> logged finishes, your console is left in whatever color the
> last log message was printed in.
> The following patch fixes the problem:
>
>
> --- C:\TEMP\log4net-1.2.0-beta8\src\Appender\ColoredConsoleAppender.cs
> Mon Jul 07 01:05:02 2003
> +++ C:\Program
> Files\log4net\log4net-1.2.0-beta8\src\Appender\ColoredConsoleA
> ppender.cs
> Wed Jan 26 13:00:00 2005
> @@ -275,6 +275,11 @@
> uiColorInfo = (uint)colLookup;
> }
>
> + // Save existing console colors
> +
> + CONSOLE_SCREEN_BUFFER_INFO originalBufferInfo;
> + GetConsoleScreenBufferInfo(iConsoleHandle, out
> originalBufferInfo);
> +
> // set the console.
> SetConsoleTextAttribute(iConsoleHandle,
> uiColorInfo);
>
> @@ -287,6 +292,9 @@
>
> (UInt32)strLoggingMessage.Length,
> out
> (UInt32)uiWritten,
> IntPtr.Zero);
> +
> + // Restore original colors
> + SetConsoleTextAttribute(iConsoleHandle,
> originalBufferInfo.wAttributes);
> }
>
> /// <summary>
> @@ -346,6 +354,36 @@
> [DllImport("Kernel32.dll", SetLastError=true,
> CharSet=CharSet.Auto)]
> private static extern IntPtr GetStdHandle(
> UInt32 uiType);
> +
> + [StructLayout(LayoutKind.Sequential)]
> + struct COORD
> + {
> + public short x;
> + public short y;
> + }
> +
> + [StructLayout(LayoutKind.Sequential)]
> + struct SMALL_RECT
> + {
> + public short Left;
> + public short Top;
> + public short Right;
> + public short Bottom;
> + }
> +
> + [StructLayout(LayoutKind.Sequential)]
> + struct CONSOLE_SCREEN_BUFFER_INFO
> + {
> + public COORD dwSize;
> + public COORD dwCursorPosition;
> + public uint wAttributes;
> + public SMALL_RECT srWindow;
> + public COORD dwMaximumWindowSize;
> + }
> +
> + [DllImport("kernel32.dll",
> EntryPoint="GetConsoleScreenBufferInfo", SetLastError=true,
> CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
> + private static extern int
> GetConsoleScreenBufferInfo(IntPtr hConsoleHandle, out
> CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
> +
>
> #endregion
> }
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic