private bool TryCreateParser(ILogEntryParserPlugin plugin, IServiceContainer services, ILogFileFormat format, out ILogEntryParser parser) { try { var rawParser = plugin.CreateParser(services, format); if (rawParser == null) { parser = null; return(false); } // We cannot trust plugins to adhere to the contract set up by the interface. // Therefore we wrap the "raw" plugin implementation by a layer which ensures that the plugin cannot screw up too bad parser = new NoThrowLogEntryParser(rawParser); return(true); } catch (Exception e) { Log.DebugFormat("Caught exception: {0}", e); parser = null; return(false); } }
/// <summary> /// Initializes this object. /// </summary> /// <param name="source"></param> /// <param name="parser"></param> public GenericTextLogSource(ILogSource source, ILogEntryParser parser) { _source = source ?? throw new ArgumentNullException(nameof(source)); _parser = parser; _parsedColumns = _parser.Columns.ToList(); _allColumns = _source.Columns.Concat(_parsedColumns).Distinct().ToList(); _listeners = new ProxyLogListenerCollection(source, this); _nothingParsed = new ReadOnlyLogEntry(_parsedColumns); }
//что бы не создавать фабрику для примера, просто обьявил метод static LogEntryReader CreateLogEntryReaderWithParser(string content, ILogEntryParser logEntryParser) { //Arrange var memoryStream = new MemoryStream(); StreamWriter sw = new StreamWriter(memoryStream); sw.WriteLine(content); sw.Flush(); memoryStream.Position = 0; return(new LogEntryReader(memoryStream, logEntryParser)); }
public LogEntryReaderFixture WithParser(ILogEntryParser parser) { _parser = parser; return(this); }
public LogFileWatcherBase(IFileWithPosition file, ILogEntryParser <TLogEntry> parser, Invoker invoker) { this.File = file; this.parser = parser; this.invoker = invoker ?? DirectInvoker.Invoke; }
public NoThrowLogEntryParser(ILogEntryParser inner) { _inner = inner; }
public Poller(IFileWithPosition file, long duration, ILogEntryParser <TLogEntry> parser, Invoker invoker = null) : base(file, parser, invoker) { this.duration = duration; }
public LogEntryReader(Stream stream, ILogEntryParser logEntryParser) { _stream = stream; _logEntryParser = logEntryParser; }
public Watcher(IFileWithPosition file, ILogEntryParser <TLogEntry> parser, Invoker invoker = null) : base(file, parser, invoker) { }