[hyena] Save STDOUT to log file on Windows so not lost



commit f9ca5b796ac3c86818f23b54b0cff93b86a8c40f
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Sat Feb 19 16:07:58 2011 -0600

    Save STDOUT to log file on Windows so not lost
    
    Only if not running uninstalled (eg from an IDE)

 Hyena/Hyena/Log.cs |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/Hyena/Hyena/Log.cs b/Hyena/Hyena/Log.cs
index 6a925fb..5a659f2 100644
--- a/Hyena/Hyena/Log.cs
+++ b/Hyena/Hyena/Log.cs
@@ -91,6 +91,20 @@ namespace Hyena
 
     public static class Log
     {
+        static Log ()
+        {
+            // On Windows, if running uninstalled, leave STDOUT alone so it's visible in the IDE,
+            // otherwise write it to a file so it's not lost.
+            if (PlatformDetection.IsWindows && !ApplicationContext.CommandLine.Contains ("uninstalled")) {
+                var log_path = Paths.Combine (Paths.ApplicationData, "log");
+                Console.WriteLine ("Logging to {0}", log_path);
+
+                var log_writer = new System.IO.StreamWriter (log_path, false);
+                log_writer.AutoFlush = true;
+                Console.SetOut (log_writer);
+            }
+        }
+
         public static event LogNotifyHandler Notify;
 
         private static Dictionary<uint, DateTime> timers = new Dictionary<uint, DateTime> ();



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