[tomboy] Add support for console logging on windows (in VS or from a cmd.exe), by attaching to the parent pro



commit af59b11ef1d1d6d8b06886fe37426e2d50bf7a57
Author: Benjamin.Podszun <benjamin podszun gmail com>
Date:   Wed Apr 29 17:06:01 2009 +0200

    Add support for console logging on windows (in VS or from a cmd.exe), by attaching to the parent processes' console if possible
---
 Tomboy/Logger.cs |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Tomboy/Logger.cs b/Tomboy/Logger.cs
index b042ba8..c5eef22 100644
--- a/Tomboy/Logger.cs
+++ b/Tomboy/Logger.cs
@@ -20,6 +20,24 @@ namespace Tomboy
 
 	class ConsoleLogger : ILogger
 	{
+#if WIN32
+		[DllImport("kernel32.dll")]
+		public static extern bool AttachConsole (uint dwProcessId);
+		const uint ATTACH_PARENT_PROCESS = 0x0ffffffff;
+		[DllImport("kernel32.dll")]
+		public static extern bool FreeConsole ();
+
+		public ConsoleLogger ()
+		{
+			AttachConsole (ATTACH_PARENT_PROCESS);
+		}
+
+		~ConsoleLogger ()
+		{
+			FreeConsole ();
+		}
+#endif
+
 		public void Log (Level lvl, string msg, params object[] args)
 		{
 			msg = string.Format ("[{0}]: {1}", Enum.GetName (typeof (Level), lvl), msg);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]