public void AddInfoLog(string title, string content) { string msg = "【" + title + "】" + content; LogsQueue.Enqueue(msg); string logMsg = String.Format("{{0}} {1}", Times.GetDateNow(), msg); }
/// <summary> /// Start the logging queue /// </summary> public async Task StartLogging() { await StopLoggingAsync(); LogsQueue.RemoveAll(); RunFunctionCancelTokenSource = new CancellationTokenSource(); RunFunctionTask = RunLogging(RunFunctionCancelTokenSource.Token); }
// 【线程函数】数据库写入数据的线程 private void LogThreadMethod() { Thread.Sleep(3000); while (true) { if (LogsQueue.Count != 0) { try { string logstring = LogsQueue.Dequeue(); Logger.WriteLog_info(typeof(Form1), logstring); bool scroll = false; MessageListControl.Invoke(new Action(() => { #region 写入到测试窗口 int FullIndex = MessageListControl.ItemHeight == 0 ? 0 : MessageListControl.Items.Count - (int)(MessageListControl.Height / MessageListControl.ItemHeight); if (MessageListControl.TopIndex == FullIndex) { scroll = true; } MessageListControl.Items.Add(string.Format("[{0}]-{1}", Times.GetDateNow(), logstring)); if (scroll) { MessageListControl.TopIndex = FullIndex; } if (MessageListControl.Items.Count > log_length) { MessageListControl.Items.Clear(); } #endregion })); } catch { } } Thread.Sleep(25); } }
/// <summary> /// Add a log to the logging queue /// </summary> public void AddLog(LogEventArgs log) { LogsQueue.Enqueue(log); NotifyAddedLog.Release(); }
public void AddErrorLog(string title, Exception e) { LogsQueue.Enqueue("【" + title + "】" + e.Message); }
public void AddInfoLog(string title) { LogsQueue.Enqueue("【" + title + "】"); }