public JournalRTRecorder(Stream stream, IJournal journal, Encoding encoding, bool forceFlush) : base(stream, encoding) { ForceFlush = forceFlush; _journal = journal; _journal.AddingNew += new AddingNewEventHandler(_journal_AddingNew); WriteStartDocument(); Formatting = Formatting.Indented; WriteStartElement("EventJournal"); WriteAttributeString("Type", _journal.GetType().AssemblyQualifiedName); WriteAttributeString("Version", Assembly.GetAssembly(_journal.GetType()).GetName().Version.ToString()); ToXml(this, _journal.EventJournalHeader, "Header"); WriteStartElement("Entries"); }
public JournalBufferedRecorder(string fileName, IJournal journal, bool forceFlush = false) : base(fileName, Encoding.Default) { if (journal == null) { throw new ArgumentNullException("journal"); } this.ForceFlush = forceFlush; this.Formatting = Formatting.Indented; _journal = journal; _journal.AddingNew += _journal_AddingNew; WriteStartDocument(); WriteStartElement("EventJournal"); WriteAttributeString("Type", _journal.GetType().AssemblyQualifiedName); WriteAttributeString("Version", Assembly.GetAssembly(_journal.GetType()).GetName().Version.ToString()); AddItem("Header", _journal.EventJournalHeader); WriteStartElement("Entries"); _addEntryTask = Task.Run( () => { foreach (var item in _buffer.GetConsumingEnumerable()) { AddItem("Entry", item); if (this.ForceFlush) { Flush(); } } }); }