public LogWindow(string Text) { InitializeComponent(); LogTextBox.Text = Text; LogTextBox.Select(Text.Length, 0); }
/// <summary> /// implement interface of ILogControl /// push log data into threadpool, it will be invoker by main thread async /// </summary> /// <param name="level"></param> /// <param name="msg"></param> /// <param name="ex"></param> public void DoLog(LoggingEvent loggingEvent) { if (InvokeRequired) { MethodInvoker invoker = () => DoLog(loggingEvent); ThreadPool.QueueUserWorkItem(this.InvokeMethod, invoker); return; } String msg = String.Format("{0} - {1},{2:D3} - {3} - T[{4}] - [ {5} ] {6}\n", loggingEvent.LoggerName, loggingEvent.TimeStamp, loggingEvent.TimeStamp.Millisecond, loggingEvent.Level, loggingEvent.ThreadName, loggingEvent.MessageObject, loggingEvent.ExceptionObject); lock (logLock) { Color color = Color.Black; switch (loggingEvent.Level.Name) { case "DEBUG": color = Color.Navy; break; case "INFO": color = Color.Navy; break; case "WARN": color = Color.DarkGoldenrod; break; case "ERROR": color = Color.Red; break; case "FATAL": color = Color.Red; break; } int start = LogTextBox.Text.Length; LogTextBox.AppendText(msg); LogTextBox.Select(start, msg.Length); LogTextBox.SelectionColor = color; LogTextBox.SelectionLength = 0; } }
//---------------------------------------------------------------------- public void AppendAndScrollText(string text) { if (InvokeRequired) { Invoke(new Action <string>(AppendAndScrollText), new[] { text }); } else { var startIndex = LogTextBox.TextLength; LogTextBox.AppendText(text + Environment.NewLine); var endIndex = LogTextBox.TextLength; LogTextBox.Select(startIndex, endIndex - startIndex); LogTextBox.ScrollToCaret(); } }
private void AddLogLine(Utility.Logger.LogData data) { if (ContextMenuLog_Inverted.Checked) { LogTextBox.ReadOnly = false; if (LogTextBox.Lines.Length > 299) { SuspendDrawLog(); LogTextBox.Select(LogTextBox.GetFirstCharIndexFromLine(200), LogTextBox.TextLength); LogTextBox.SelectedText = ""; SuspendDrawLog(false); } LogTextBox.SelectionStart = 0; LogTextBox.SelectionLength = 0; LogTextBox.SelectionFont = Utility.Configuration.Config.UI.JapFont; if (ContextMenuLog_CompactMode.Checked) { LogTextBox.SelectedText = string.Format("[{0:HH:mm:ss}] {1}", data.Time, data.Message); } else { LogTextBox.SelectedText = string.Format("[{0}][{1}] : {2}", Utility.Mathematics.DateTimeHelper.TimeToCSVString(data.Time), data.Priority, data.Message); } LogTextBox.SelectionFont = Utility.Configuration.Config.UI.MainFont; LogTextBox.SelectedText = data.MsgChs1; LogTextBox.SelectionFont = Utility.Configuration.Config.UI.JapFont; LogTextBox.SelectedText = data.MsgJap2; LogTextBox.SelectionFont = Utility.Configuration.Config.UI.MainFont; LogTextBox.SelectedText = data.MsgChs2; LogTextBox.SelectionFont = Utility.Configuration.Config.UI.JapFont; LogTextBox.SelectedText = data.MsgJap3; LogTextBox.SelectionFont = Utility.Configuration.Config.UI.MainFont; LogTextBox.SelectedText = data.MsgChs3; LogTextBox.SelectedText = "\r\n"; LogTextBox.ReadOnly = true; ScrollLog(SB_PAGETOP); } else { if (LogTextBox.Lines.Length > 0) { if (LogTextBox.Lines.Length > 299) // Delete first 100 lines once Log reaches 300 lines { SuspendDrawLog(); LogTextBox.ReadOnly = false; LogTextBox.Select(0, LogTextBox.GetFirstCharIndexFromLine(100)); LogTextBox.SelectedText = ""; LogTextBox.ReadOnly = true; SuspendDrawLog(false); } LogTextBox.AppendText("\r\n"); } LogTextBox.SelectionFont = Utility.Configuration.Config.UI.JapFont; if (ContextMenuLog_CompactMode.Checked) { LogTextBox.AppendText(string.Format("[{0:HH:mm:ss}] {1}", data.Time, data.Message)); } else { LogTextBox.AppendText(string.Format("[{0}][{1}] : {2}", Utility.Mathematics.DateTimeHelper.TimeToCSVString(data.Time), data.Priority, data.Message)); } LogTextBox.SelectionFont = Utility.Configuration.Config.UI.MainFont; LogTextBox.AppendText(data.MsgChs1); LogTextBox.SelectionFont = Utility.Configuration.Config.UI.JapFont; LogTextBox.AppendText(data.MsgJap2); LogTextBox.SelectionFont = Utility.Configuration.Config.UI.MainFont; LogTextBox.AppendText(data.MsgChs2); LogTextBox.SelectionFont = Utility.Configuration.Config.UI.JapFont; LogTextBox.AppendText(data.MsgJap3); LogTextBox.SelectionFont = Utility.Configuration.Config.UI.MainFont; LogTextBox.AppendText(data.MsgChs3); ScrollLog(SB_PAGEBOTTOM); } }