public void update(TraceUpdateCallback a_traceUpdateCb) { lock (m_traceQueue) { while (m_traceQueue.Count > 0) { TracerItem item = m_traceQueue.Dequeue(); if (item == null) { break; } a_traceUpdateCb(item.m_dataTime, item.m_level, item.m_context, item.m_file, item.m_line); } } }
private void _trace(ETracerLevel a_level, string a_context, string a_file, int a_line) { lock (m_traceQueue) { TracerItem item = new TracerItem(); if (item == null) { return; } item.m_dataTime = DateTime.Now; item.m_level = a_level; item.m_file = a_file; item.m_line = a_line; item.m_context = a_context; m_traceQueue.Enqueue(item); } }
void _watcher_Changed(object sender, FileSystemEventArgs e) { if (_fs == null || e.ChangeType == WatcherChangeTypes.Deleted || e.ChangeType == WatcherChangeTypes.Created) { if (_reader != null) { _reader.Dispose(); _reader = null; } if (_fs != null) { _fs.Dispose(); _fs = null; } if (e.ChangeType == WatcherChangeTypes.Deleted) { return; } try { _fs = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _reader = new StreamReader(_fs); } catch (Exception ex) { SystemMonitor.Error(ex.Message); _reader = null; _fs.Dispose(); _fs = null; return; } } if (_fs == null || _fs.CanRead == false) { return; } if (_fs.Length < _lastFilePos - 10) {// File was rewritten start from beggining. _lastFilePos = 0; } _fs.Seek(_lastFilePos, SeekOrigin.Begin); string line = _reader.ReadLine(); while (line != null) { TracerItem item = TracerItem.ParseFileItem(line); if (item != null) { _tracer.Add(item); } //ParseLine(line); line = _reader.ReadLine(); } _lastFilePos = _fs.Position; }