/[RomCheater]/trunk/RomCheater.Logging/LogWriter.cs
ViewVC logotype

Diff of /trunk/RomCheater.Logging/LogWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.Logging/LogWriter.cs	2012/05/09 08:02:18	17
+++ trunk/RomCheater.Logging/LogWriter.cs	2012/05/09 08:22:41	19
@@ -13,6 +13,9 @@
 {
     public partial class LogWriter : UserControl
     {
+        private const string LOG_FILE = "RomCheater.log";
+        private static string LOG_PATH = string.Format(@"{0}\{1}", Application.StartupPath, LOG_FILE);
+
         private delegate string OnGetLogText();
         private delegate void OnSetLogText(string value);
         private delegate void GenericVoidDelegate();
@@ -34,13 +37,19 @@
             this.RedirectConsoleOutput = redirectConsole;
             toolTip1.SetToolTip(btnClearLog, "Clears the Log");
             toolTip1.SetToolTip(btnCopyLogToClipboard, "Copies the Log to the Clipboard");
+
             ms = new MemoryStream();
             sw = new StreamWriter(ms);
             sw.AutoFlush = true;
             sr = new StreamReader(ms);
+
+            FileInfo fi = new FileInfo(LOG_PATH);
+            if (fi.Exists)
+                fi.Delete();
+
         }
         private LogStream _Log;
-        public LogStream Log { get { return _Log; } private set { _Log = value;  } }
+        public LogStream Log { get { return _Log; } private set { _Log = value; } }
 
 
         private MemoryStream ms;
@@ -55,8 +64,8 @@
             set
             {
                 _RedirectConsoleOutput = value;
-                if (value) { Console.SetOut(this.Log); } 
-                else 
+                if (value) { Console.SetOut(this.Log); }
+                else
                 {
                     Stream stream = Console.OpenStandardOutput(0x100);
                     TextWriter writer = null;
@@ -66,7 +75,7 @@
                     //writer2.HaveWrittenPreamble = true;
                     writer2.AutoFlush = true;
                     writer = TextWriter.Synchronized(writer2);
-                    Console.SetOut(writer); 
+                    Console.SetOut(writer);
                 }
             }
         }
@@ -132,6 +141,12 @@
             //{
             //    txtLog.AppendText(value);
             //}
+            FileStream fs = new FileStream(LOG_PATH, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
+            StreamWriter writer = new StreamWriter(fs);
+            writer.AutoFlush = true;
+            if (value == Log.NewLine) { writer.Write(System.Environment.NewLine); }
+            else { writer.Write(value); }
+            writer.Close();
             sw.Write(value);
         }
         new public string Text
@@ -146,7 +161,7 @@
             }
         }
 
-        public void Clear() 
+        public void Clear()
         {
             Clear(false);
         }
@@ -158,7 +173,7 @@
 #endif
             if (force || allow_log_clearing)
             {
-            
+
                 txtLog.Clear();
                 ms = new MemoryStream();
                 sw = new StreamWriter(ms);
@@ -168,7 +183,7 @@
         }
         #region sub-classes
         public class LogStream : TextWriter
-        {            
+        {
             public LogStream() : this(null) { }
             public LogStream(LogWriter text) : base() { _text_writer = text; this.NewLine = "\n"; }
             private LogWriter _text_writer;
@@ -176,8 +191,8 @@
             #region Overriden Methods
             public override Encoding Encoding { get { return Encoding.UTF8; } }
             public override void Write(char value) { base.Write(value); _write(value.ToString()); if (!_text_writer.BeginUpdate) _text_writer.EndLogUpdate(); }
-            #endregion          
+            #endregion
         }
-        #endregion        
+        #endregion
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22