--- trunk/RomCheater.Logging/LogWriter.cs 2012/05/09 08:02:18 17 +++ trunk/RomCheater.Logging/LogWriter.cs 2012/05/09 08:16:18 18 @@ -13,6 +13,9 @@ namespace RomCheater.Logging { 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 @@ namespace RomCheater.Logging 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 @@ namespace RomCheater.Logging 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 @@ namespace RomCheater.Logging //writer2.HaveWrittenPreamble = true; writer2.AutoFlush = true; writer = TextWriter.Synchronized(writer2); - Console.SetOut(writer); + Console.SetOut(writer); } } } @@ -132,6 +141,11 @@ namespace RomCheater.Logging //{ // txtLog.AppendText(value); //} + FileStream fs = new FileStream(LOG_PATH, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); + StreamWriter writer = new StreamWriter(fs); + writer.AutoFlush = true; + writer.Write(value); + writer.Close(); sw.Write(value); } new public string Text @@ -146,7 +160,7 @@ namespace RomCheater.Logging } } - public void Clear() + public void Clear() { Clear(false); } @@ -158,7 +172,7 @@ namespace RomCheater.Logging #endif if (force || allow_log_clearing) { - + txtLog.Clear(); ms = new MemoryStream(); sw = new StreamWriter(ms); @@ -168,7 +182,7 @@ namespace RomCheater.Logging } #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 +190,8 @@ namespace RomCheater.Logging #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 } } |