Exemplo n.º 1
0
        /// <summary>
        /// Adiciona as informações de logs na tela.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void WriteLog(object sender, LogEventArgs e)
        {
            RichTextBox textBox = null;

            switch ((LogType)e.Index)
            {
            case LogType.System:
                textBox = TextSystem;
                break;

            case LogType.Connection:
                textBox = TextConnection;
                break;

            case LogType.User:
                textBox = TextUser;
                break;
            }

            if (textBox.InvokeRequired)
            {
                var d = new DelegateWriteLog(WriteLog);
                textBox.Invoke(d, sender, e);
            }
            else
            {
                textBox.SelectionStart  = textBox.TextLength;
                textBox.SelectionLength = 0;
                textBox.SelectionColor  = e.Color;
                textBox.AppendText($"{DateTime.Now}: {e.Text}{Environment.NewLine}");
                textBox.ScrollToCaret();
            }
        }
Exemplo n.º 2
0
 static Log()
 {
     ErrorFile = ErrorFolder + @"\" + DateTime.Now.Date.ToString("yyyy-MM-dd") + ".Log";
     if (!Directory.Exists(ErrorFolder))
     {
         Directory.CreateDirectory(ErrorFolder);
     }
     if (!File.Exists(ErrorFile))
     {
         //异常日志不存在创建
         StreamWriter write = File.CreateText(ErrorFile);
         write.WriteLine("----------LOG----------");
         write.Close();
     }
     wlog += new DelegateWriteLog(Write);
 }
Exemplo n.º 3
0
        public void WriteLog(object sender, LogEventArgs e)
        {
            if (!ServerRunning)
            {
                return;
            }

            if (TextLog.InvokeRequired)
            {
                var d = new DelegateWriteLog(WriteLog);
                TextLog.Invoke(d, sender, e);
            }
            else
            {
                TextLog.SelectionStart  = TextLog.TextLength;
                TextLog.SelectionLength = 0;
                TextLog.SelectionColor  = e.Color;
                TextLog.AppendText($"{DateTime.Now}: {e.Text}{Environment.NewLine}");
                TextLog.ScrollToCaret();
            }
        }
Exemplo n.º 4
0
        public void WriteLog(string text, Color color)
        {
            if (closing)
            {
                return;
            }

            if (TextLogs.InvokeRequired)
            {
                var d = new DelegateWriteLog(WriteLog);
                TextLogs.Invoke(d, text, color);
            }
            else
            {
                TextLogs.SelectionStart  = TextLogs.TextLength;
                TextLogs.SelectionLength = 0;
                TextLogs.SelectionColor  = color;
                TextLogs.AppendText($"{DateTime.Now}: {text}{Environment.NewLine}");
                TextLogs.SelectionColor = color;
                TextLogs.ScrollToCaret();
            }
        }