Beispiel #1
0
        public RollingFilesMedia(
            LogMedia.IFileSystem fileSystem,
            Type logReaderType,
            StreamBasedFormatInfo logFormatInfo,
            LJTraceSource traceSource,
            IRollingFilesMediaStrategy rollingStrategy,
            ITempFilesManager tempFilesManager,
            ITraceSourceFactory traceSourceFactory)
        {
            this.traceSourceFactory = traceSourceFactory;
            trace = traceSource;
            using (trace.NewFrame)
            {
                if (fileSystem == null)
                {
                    throw new ArgumentNullException("fileSystem");
                }

                this.rollingStrategy  = rollingStrategy;
                this.logReaderType    = logReaderType;
                this.logFormatInfo    = logFormatInfo;
                this.tempFilesManager = tempFilesManager;

                try
                {
                    this.fileSystem    = fileSystem;
                    this.baseDirectory = rollingStrategy.BaseDirectory;
                    trace.Info("Base file directory: {0}", baseDirectory);

                    this.concatStream = new ConcatReadingStream();
                    this.tempThreads  = new LogSourceThreads(LJTraceSource.EmptyTracer, new ModelThreads(), null);

                    this.fsWatcher                     = fileSystem.CreateWatcher();
                    this.fsWatcher.Path                = this.baseDirectory;
                    this.fsWatcher.Created            += new FileSystemEventHandler(fsWatcher_Created);
                    this.fsWatcher.Renamed            += new RenamedEventHandler(fsWatcher_Renamed);
                    this.fsWatcher.EnableRaisingEvents = true;

                    trace.Info("Watcher enabled");

                    this.folderNeedsRescan = 1;
                }
                catch
                {
                    trace.Error("Initialization failed. Disposing.");
                    Dispose();
                    throw;
                }
            }
        }
        public StreamLogProvider(
            ILogProviderHost host,
            ILogProviderFactory factory,
            IConnectionParams connectParams,
            StreamBasedFormatInfo formatInfo,
            Type readerType
            ) :
            base(host, factory, connectParams)
        {
            using (tracer.NewFrame)
            {
                tracer.Info("readerType={0}", readerType);

                if (connectionParams[ConnectionParamsKeys.RotatedLogFolderPathConnectionParam] != null)
                {
                    media = new RollingFilesMedia(
                        LogMedia.FileSystemImpl.Instance,
                        readerType,
                        formatInfo,
                        tracer,
                        new GenericRollingMediaStrategy(connectionParams[ConnectionParamsKeys.RotatedLogFolderPathConnectionParam]),
                        host.TempFilesManager,
                        host.TraceSourceFactory
                        );
                }
                else
                {
                    media = new SimpleFileMedia(connectParams);
                }

                reader = (IPositionedMessagesReader)Activator.CreateInstance(
                    readerType, new MediaBasedReaderParams(this.threads, media, host.TempFilesManager, host.TraceSourceFactory,
                                                           settingsAccessor: host.GlobalSettings, parentLoggingPrefix: tracer.Prefix), formatInfo);

                ITimeOffsets initialTimeOffset;
                if (LogJoint.TimeOffsets.TryParse(
                        connectionParams[ConnectionParamsKeys.TimeOffsetConnectionParam] ?? "", out initialTimeOffset))
                {
                    reader.TimeOffsets = initialTimeOffset;
                }

                StartAsyncReader("Reader thread: " + connectParams.ToString(), reader);

                InitPathDependentMembers(connectParams);
            }
        }