public NoThrowLogFileFormatMatcher(ILogFileFormatMatcherPlugin plugin, IServiceContainer services) { try { _inner = plugin.CreateMatcher(services); } catch (Exception e) { Log.ErrorFormat("Caught unexpected exception: {0}", e); } }
/// <summary> /// Initializes this text log file. /// </summary> /// <remarks> /// Plugin authors are deliberately prevented from calling this constructor directly because it's signature may change /// over time. In order to create an instance of this type, simply call <see cref="IServiceContainer.CreateTextLogFile"/>. /// </remarks> /// <param name="scheduler"></param> /// <param name="fileName"></param> /// <param name="timestampParser">An optional timestamp parser that is used to find timestamps in log messages. If none is specified, then <see cref="TimestampParser"/> is used</param> /// <param name="translator">An optional translator that is used to translate each log line in memory. If none is specified, then log lines are displayed as they are in the file on disk</param> /// <param name="encoding">The encoding to use to interpet the file, if none is specified, then <see cref="Encoding.UTF8"/> is used</param> /// <param name="formatMatcher"></param> internal TextLogFile(ITaskScheduler scheduler, string fileName, ITimestampParser timestampParser = null, ILogLineTranslator translator = null, Encoding encoding = null, ILogFileFormatMatcher formatMatcher = null) : base(scheduler) { _fileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); _fullFilename = fileName; if (!Path.IsPathRooted(_fullFilename)) { _fullFilename = Path.Combine(Directory.GetCurrentDirectory(), fileName); } if (translator != null) { _translator = new NoThrowLogLineTranslator(translator); } _formatMatcher = formatMatcher; _entries = new List <LogLine>(); _properties = new LogFilePropertyList(LogFileProperties.Minimum); _properties.SetValue(LogFileProperties.Name, _fileName); _syncRoot = new object(); _encoding = encoding ?? Encoding.UTF8; _properties.SetValue(LogFileProperties.Encoding, encoding); Log.DebugFormat("Log File '{0}' is interpreted using {1}", _fileName, _encoding.EncodingName); if (timestampParser != null) { _timestampParser = new NoThrowTimestampParser(timestampParser); } else { _timestampParser = new TimestampParser(); } StartTask(); }
public FileFormatDetector(ILogFileFormatMatcher formatMatcher) { _formatMatcher = formatMatcher; }