Beispiel #1
0
        // Log 调用 注意Warning和Error时应有第二个参数 不换行有第三参数为false
        public void Log_Terminal(string log, logType logtype = logType.CommonLog, bool addNewLine = true)
        {
            if (addNewLine)
            {
                log += Environment.NewLine;
            }

            Color color = new Color();

            switch (logtype)
            {
            case logType.CommonLog:
                color = Color.Green;
                break;

            case logType.Warning:
                color = Color.Orange;
                break;

            case logType.Error:
                color = Color.Red;
                break;
            }

            Terminal.SelectionStart  = Terminal.TextLength;
            Terminal.SelectionLength = 0;
            Terminal.SelectionColor  = color;

            string text = $@"[{DateTime.Now.ToLongTimeString()}] {log}";

            Terminal.Focus(); //warning:这句话没有的话会使得terminal不能跟踪到最新的log
            Terminal.AppendText(text);

            Terminal.SelectionColor = Terminal.ForeColor;
        }