private void CollectionViewSource_Filter(object sender, FilterEventArgs e) { C_LogMsg t = e.Item as C_LogMsg; if (t != null) { e.Accepted = false; foreach (e_LogMsgSource src in lsLogSrcSelction.SelectedItems) { if (src == t.src) { e.Accepted = true; // If filter is turned on, filter completed items. } } } }
public void ADD_toBuffer(C_LogMsg _logMsg) { #if (!DEBUG) // don't log unimportant and log msgs when not debugging if ((_logMsg.src == e_LogMsgSource.unimportant) || (_logMsg.src == e_LogMsgSource.debug)) { return; } #endif //if (fileIsOpen == false) //{ // OPEN_file(filePath); //} // loger must trigger its collection update after some reasonable intervals - otherwise the program stops due to too quick collection updates triggers and handlers lock (msgList_locker) { try { if (msgList.Last().time == _logMsg.time) // multiple at the same time { _logMsg.queue = msgList.Last().queue + 1; //_logMsg.queue = msgListBuffer.Last().queue + 1; } msgList.Add(_logMsg); //msgListBuffer.Add(_logMsg); using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true)) { file.WriteLine(_logMsg.ToString()); } if (trimMsgBuffer == true) { if (logMsgCount > logMsgCountMaximum + trimTriggerCount) { msgList = new ObservableCollection <C_LogMsg>( msgList.Skip((int)(logMsgCountMaximum - logMsgCount)) ); logMsgCount = logMsgCountMaximum; } else if (logMsgCount == logMsgCountMaximum) { msgList.RemoveAt(0); } else { logMsgCount++; } } else { logMsgCount++; } errorAntiLoopCounter = 0; } catch (Exception e) { string err_str = string.Format("Cannot add item to dataGrid:\n{0}\n{1}", e.Data, e.Message); errorAntiLoopCounter++; if (errorAntiLoopCounter < errorAntiLoopCounter_max) { // try to log it again LOG_err(e_LogMsgSource.log, err_str); } else { Console.WriteLine(err_str); errorAntiLoopCounter = 0; } } } }
public void LOG(C_LogMsg _msg) { ADD_toBuffer(_msg); }