コード例 #1
0
        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);
            }
        }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
ファイル: LogEntryReaderTests.cs プロジェクト: zeone/Patterns
        //что бы не создавать фабрику для примера, просто обьявил метод
        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));
        }
コード例 #4
0
ファイル: LogEntryReaderTests.cs プロジェクト: zeone/Patterns
 public LogEntryReaderFixture WithParser(ILogEntryParser parser)
 {
     _parser = parser;
     return(this);
 }
コード例 #5
0
 public LogFileWatcherBase(IFileWithPosition file, ILogEntryParser <TLogEntry> parser, Invoker invoker)
 {
     this.File    = file;
     this.parser  = parser;
     this.invoker = invoker ?? DirectInvoker.Invoke;
 }
コード例 #6
0
 public NoThrowLogEntryParser(ILogEntryParser inner)
 {
     _inner = inner;
 }
コード例 #7
0
 public Poller(IFileWithPosition file, long duration, ILogEntryParser <TLogEntry> parser, Invoker invoker = null)
     : base(file, parser, invoker)
 {
     this.duration = duration;
 }
コード例 #8
0
ファイル: LogEntryReader.cs プロジェクト: zeone/Patterns
 public LogEntryReader(Stream stream, ILogEntryParser logEntryParser)
 {
     _stream         = stream;
     _logEntryParser = logEntryParser;
 }
コード例 #9
0
 public Watcher(IFileWithPosition file, ILogEntryParser <TLogEntry> parser, Invoker invoker = null)
     : base(file, parser, invoker)
 {
 }