private void WriteLog(object sender, LogInfoArgs e) { if (e.level < LogLevel.FormLog) { return; } if (rbLog.InvokeRequired) { AppendTextCallback d = new AppendTextCallback(WriteLog); rbLog.Invoke(d, new object[] { sender, e }); } else { if (e.level == LogLevel.Error) { rbLog.SelectionColor = System.Drawing.Color.Red; } else if (e.level == LogLevel.Warning) { rbLog.SelectionColor = System.Drawing.Color.DarkViolet; } if (e.level == LogLevel.SqlExe) { rbLog.AppendText(e.info + Environment.NewLine); } else { rbLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + e.title + e.info + Environment.NewLine); } } }
// 写文本日志 public void WriteLog(string info, LogLevel level = LogLevel.Info) { LogInfoArgs e = new LogInfoArgs(info, level); try { writer.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + e.title + e.info); writer.Flush(); // 及时写入 } catch (ObjectDisposedException ex) { System.Windows.Forms.MessageBox.Show("w ObjectDisposedException\r\n" + ex.Message); } catch (IOException ex) { System.Windows.Forms.MessageBox.Show("w IOException\r\n" + ex.Message); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("w Exception\r\n" + ex.Message); } // 通知日志的订户 if (OnLogInfo != null) { OnLogInfo(this, e); } }
private void WriteLog(object sender, LogInfoArgs e) { if (e.level < LogLevel.FormLog) return; if (rbLog.InvokeRequired) { AppendTextCallback d = new AppendTextCallback(WriteLog); rbLog.Invoke(d, new object[] { sender, e }); } else { if (e.level == LogLevel.Error) { rbLog.SelectionColor = System.Drawing.Color.Red; } else if (e.level == LogLevel.Warning) { rbLog.SelectionColor = System.Drawing.Color.DarkViolet; } if (e.level == LogLevel.SqlExe) { rbLog.AppendText(e.info + Environment.NewLine); } else { rbLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + e.title + e.info + Environment.NewLine); } } }