You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Wesley Smith <We...@tdsway.com> on 2005/01/27 21:03:07 UTC

Patch to allow large messages to be logged via ColoredConsoleAppender

I found that if you attempt to log a message of more than about 26000
characters, ColoredConsoleAppender will not log the message (no error,
just silently eats the message).  One possible fix for the problem is
given in the patch below:


--- 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\ColoredConsoleAppender.cs
Wed Jan 26 12:57:22 2005
@@ -280,13 +280,32 @@
 
 			string strLoggingMessage =
RenderLoggingEvent(loggingEvent);
 
-			// write the output.
 			UInt32 uiWritten = 0;
+
+			// WriteConsoleW can only handle a limited
number of characters at a time
+			// and emperically, 26000 is about right.
+			const int maxChunkSize = 26000;
+			while (strLoggingMessage.Length > maxChunkSize) 
+			{
+				string firstPart =
strLoggingMessage.Substring(0, maxChunkSize);
+				WriteConsoleW(	iConsoleHandle,
+					firstPart,
+					(UInt32)firstPart.Length,
+					out (UInt32)uiWritten,
+					IntPtr.Zero);
+
+				// Remove the characters already output
from strLoggingMessage
+				strLoggingMessage =
strLoggingMessage.Substring(maxChunkSize);
+
+			}
+			// write the remaining output.
+			
 			WriteConsoleW(	iConsoleHandle,
 
strLoggingMessage,
 
(UInt32)strLoggingMessage.Length,
 							out
(UInt32)uiWritten,
 							IntPtr.Zero);
+
 		}
 
 		/// <summary>