/// <summary> /// Initalizes this object. /// </summary> /// <param name="translator"></param> public NoThrowLogLineTranslator(ILogLineTranslator translator) { if (translator == null) { throw new ArgumentNullException(nameof(translator)); } _translator = translator; }
/// <summary> /// Initializes this text log file. /// </summary> /// <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> public TextLogFile(ITaskScheduler scheduler, string fileName, ITimestampParser timestampParser = null, ILogLineTranslator translator = null, Encoding encoding = null) : base(scheduler) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } _fileName = fileName; _fullFilename = fileName; if (!Path.IsPathRooted(_fullFilename)) { _fullFilename = Path.Combine(Directory.GetCurrentDirectory(), fileName); } if (translator != null) { _translator = new NoThrowLogLineTranslator(translator); } _entries = new List <LogLine>(); _properties = new LogFilePropertyList(LogFileProperties.Minimum); _properties.SetValue(LogFileProperties.Name, _fileName); _syncRoot = new object(); _encoding = encoding ?? Encoding.UTF8; Log.DebugFormat("Log File '{0}' is interpreted using {1}", _fileName, _encoding.EncodingName); if (timestampParser != null) { _timestampParser = new NoThrowTimestampParser(timestampParser); } else { _timestampParser = new TimestampParser(); } StartTask(); }