void LogWriterRun() { var sw = new StreamWriter(Environment.CurrentDirectory + Constants.LogDirSuffix + "\\" + _StartupDate.ToString(Constants.LogFileName) + ".log", true); while (!_disposing || LogWriterToDo.Count > 0) { Thread.Sleep(3000); while (LogWriterToDo.Count > 0) { var item = LogWriterToDo.First(); sw.Write(item); sw.Flush(); LogWriterToDo.Remove(item); } } sw.Close(); }
internal void Log(MessageStatus Status, string Txt) { DateTime logTime = DateTime.Now; StringBuilder sb = new StringBuilder(); sb.Append(Environment.NewLine); sb.AppendFormat("[{0}] [{1}]: ", logTime.ToString("HH:mm:ss"), Status.Status); if (Status == MessageStatus.Request) { sb.Append(">> "); } else if (Status == MessageStatus.Response) { sb.Append("<< "); } if (Txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Count() < 2) { sb.Append(Txt); } else { foreach (var part in Txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) { sb.Append(Environment.NewLine); sb.Append(part); } } LogWriterToDo.Add(sb.ToString()); //if (!_logger.IsAlive) //{ // _logger.Start(); //} _PrintConsole(Status, Txt); }