private TextStyle _getTextStyleFromLogLevel(Dirac.Logging.Logger.Level level) { switch (level) { case Logger.Level.Trace: case Logger.Level.PacketDump: return(this.traceStyle); case Logger.Level.Debug: return(this.debugStyle); case Logger.Level.Info: return(this.infoStyle); case Logger.Level.Warn: return(this.warnStyle); case Logger.Level.Error: return(this.errorStyle); case Logger.Level.Fatal: return(this.fatalStyle); default: return(this.traceStyle); } }
public void AddTextToFastColoredTextBox(String text, Dirac.Logging.Logger.Level level) { TextStyle style = this._getTextStyleFromLogLevel(level); if (this.fastColoredTextBox1.InvokeRequired) { Action action_append_text = () => { //some stuffs for best performance fastColoredTextBox1.BeginUpdate(); fastColoredTextBox1.Selection.BeginUpdate(); //remember user selection var userSelection = fastColoredTextBox1.Selection.Clone(); //add text with predefined style fastColoredTextBox1.TextSource.CurrentTB = fastColoredTextBox1; fastColoredTextBox1.AppendText(text, style); //restore user selection if (!userSelection.IsEmpty || userSelection.Start.iLine < fastColoredTextBox1.LinesCount - 2) { fastColoredTextBox1.Selection.Start = userSelection.Start; fastColoredTextBox1.Selection.End = userSelection.End; } else { fastColoredTextBox1.GoEnd();//scroll to end of the text } // fastColoredTextBox1.Selection.EndUpdate(); fastColoredTextBox1.EndUpdate(); this.fastColoredTextBox1.GoEnd(); }; this.Invoke(action_append_text, null); } else { //this.fastColoredTextBox1.AppendText(line + Environment.NewLine, textStyle); //this.fastColoredTextBox1.GoEnd(); } }