/// <summary> /// Initializes this text log file. /// </summary> /// <param name="taskScheduler"></param> /// <param name="fileName"></param> /// <param name="format"></param> /// <param name="encoding"></param> internal StreamingTextLogSource(ITaskScheduler taskScheduler, string fileName, ILogFileFormat format, Encoding encoding) { _taskScheduler = taskScheduler; _encoding = encoding; _listeners = new LogSourceListenerCollection(this); _sourceDoesNotExist = new SourceDoesNotExist(fileName); _sourceCannotBeAccessed = new SourceCannotBeAccessed(fileName); _fileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); _index = new LogBufferList(StreamingTextLogSource.LineOffsetInBytes); _propertiesBuffer = new PropertiesBufferList(); _propertiesBuffer.SetValue(Core.Properties.Name, _fileName); _propertiesBuffer.SetValue(Core.Properties.Format, format); _propertiesBuffer.SetValue(TextProperties.RequiresBuffer, true); _propertiesBuffer.SetValue(TextProperties.LineCount, 0); _properties = new ConcurrentPropertiesList(Core.Properties.Minimum); SynchronizeProperties(); _cancellationTokenSource = new CancellationTokenSource(); _columns = new IColumnDescriptor[] { Core.Columns.Index, StreamingTextLogSource.LineOffsetInBytes, Core.Columns.RawContent }; _pendingReadRequests = new ConcurrentQueue <IReadRequest>(); _fileScanTask = _taskScheduler.StartPeriodic(() => RunFileScan(_cancellationTokenSource.Token)); _fileReadTask = _taskScheduler.StartPeriodic(() => RunFileRead(_cancellationTokenSource.Token)); }
public FileLogSource(IServiceContainer services, string fileName, TimeSpan maximumWaitTime) : base(services.Retrieve <ITaskScheduler>()) { _syncRoot = new object(); _filesystem = services.Retrieve <IFilesystem>(); _services = services; _fullFilename = Path.IsPathRooted(fileName) ? fileName : Path.Combine(Directory.GetCurrentDirectory(), fileName); _maximumWaitTime = maximumWaitTime; _sourceDoesNotExist = new SourceDoesNotExist(fileName); _sourceCannotBeAccessed = new SourceCannotBeAccessed(fileName); var formatMatcher = services.Retrieve <ILogFileFormatMatcher>(); _encodingDetector = new EncodingDetector(); _formatDetector = new FileFormatDetector(formatMatcher); _buffer = new LogBufferArray(MaximumLineCount, Core.Columns.RawContent); _pendingSections = new ConcurrentQueue <KeyValuePair <ILogSource, LogSourceModification> >(); _propertiesBuffer = new PropertiesBufferList(); _propertiesBuffer.SetValue(Core.Properties.Name, _fullFilename); _properties = new ConcurrentPropertiesList(); StartTask(); }
private Stream TryOpenRead(string fileName, out IEmptyReason error) { try { error = null; return(_filesystem.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)); } catch (FileNotFoundException e) { error = _sourceDoesNotExist; Log.Debug(e); } catch (DirectoryNotFoundException e) { error = _sourceDoesNotExist; Log.Debug(e); } catch (UnauthorizedAccessException e) { error = _sourceCannotBeAccessed; Log.Debug(e); } catch (IOException e) { error = _sourceCannotBeAccessed; Log.Debug(e); } return(null); }
private void SetError(IEmptyReason emptyReason) { _propertiesBuffer.SetValue(Core.Properties.Format, null); _propertiesBuffer.SetValue(TextProperties.ByteOrderMark, null); _propertiesBuffer.SetValue(TextProperties.AutoDetectedEncoding, null); _propertiesBuffer.SetValue(TextProperties.Encoding, null); _propertiesBuffer.SetValue(TextProperties.MaxCharactersInLine, _maxCharactersInLine = 0); _propertiesBuffer.SetValue(Core.Properties.EmptyReason, emptyReason); _propertiesBuffer.SetValue(Core.Properties.Created, _lastFingerprint?.Created); _propertiesBuffer.SetValue(Core.Properties.LastModified, _lastFingerprint?.LastModified); }
private void SetError(IEmptyReason emptyReason) { _propertiesBuffer.SetValue(Core.Properties.EmptyReason, emptyReason); _propertiesBuffer.SetValue(Core.Properties.Created, null); _propertiesBuffer.SetValue(Core.Properties.Size, null); _propertiesBuffer.SetValue(Core.Properties.PercentageProcessed, Percentage.HundredPercent); _propertiesBuffer.SetValue(Core.Properties.LastModified, null); _propertiesBuffer.SetValue(Core.Properties.Created, null); _propertiesBuffer.SetValue(Core.Properties.Size, null); _propertiesBuffer.SetValue(TextProperties.LineCount, 0); _propertiesBuffer.SetValue(Core.Properties.LogEntryCount, 0); ResetIndex(); }
/// <summary> /// Initializes this text log file. /// </summary> /// <param name="filesystem"></param> /// <param name="taskScheduler"></param> /// <param name="fileName"></param> /// <param name="format"></param> /// <param name="encoding"></param> internal TextLogSource(IFilesystem filesystem, ITaskScheduler taskScheduler, string fileName, ILogFileFormat format, Encoding encoding) : base(taskScheduler) { _filesystem = filesystem; _fileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); _encoding = encoding ?? throw new ArgumentNullException(nameof(encoding)); _entries = new LogBufferList(Core.Columns.RawContent); _columns = new IColumnDescriptor[] { Core.Columns.Index, Core.Columns.OriginalIndex, Core.Columns.LogEntryIndex, Core.Columns.LineNumber, Core.Columns.OriginalLineNumber, Core.Columns.OriginalDataSourceName, Core.Columns.RawContent, PageBufferedLogSource.RetrievalState }; _sourceDoesNotExist = new SourceDoesNotExist(fileName); _sourceCannotBeAccessed = new SourceCannotBeAccessed(fileName); _localProperties = new PropertiesBufferList(Core.Properties.Minimum); _localProperties.SetValue(Core.Properties.Name, _fileName); _localProperties.Add(TextProperties.LineCount); _localProperties.SetValue(Core.Properties.Format, format); _localProperties.SetValue(TextProperties.LineCount, 0); _localProperties.SetValue(TextProperties.RequiresBuffer, false); _properties = new ConcurrentPropertiesList(Core.Properties.Minimum); SynchronizePropertiesWithUser(); _syncRoot = new object(); _properties.SetValue(TextProperties.AutoDetectedEncoding, encoding); Log.DebugFormat("Log File '{0}' is interpreted using {1}", _fileName, _encoding.EncodingName); StartTask(); }
private void SetError(IEmptyReason emptyReason) { _localProperties.SetValue(Core.Properties.EmptyReason, emptyReason); SynchronizePropertiesWithUser(); SetEndOfSourceReached(); }