Пример #1
0
        public SizeRollingFileSink(
            string filePathTemplate,
            ITextFormatter formatter,
            long fileSizeLimitBytes,
            int retainedFileCountLimit,
            Encoding encoding = null)
        {
            this.filePathTemplate       = filePathTemplate;
            this.filePathDirectory      = Path.GetDirectoryName(filePathTemplate);
            this.fileSizeLimitBytes     = fileSizeLimitBytes;
            this.retainedFileCountLimit = retainedFileCountLimit;

            this.fileSinkFactory = new FileSinkFactory(formatter, this.filePathTemplate, this.fileSizeLimitBytes, encoding);

            this.currentSink = this.fileSinkFactory.GetNewSink();
            FileSinkRoller.RemoveObsoleteFileSinks(this.fileSinkFactory.GetObsoleteFileSinks(this.retainedFileCountLimit), this.filePathDirectory);
        }
Пример #2
0
        public void Emit(LogEvent logEvent)
        {
            this.ValidateSinkAndLogState(logEvent);

            lock (this.syncRoot)
            {
                if (this.currentSink.SizeLimitReached)
                {
                    this.currentSink = this.fileSinkFactory.GetNextSink(this.currentSink);
                    FileSinkRoller.RemoveObsoleteFileSinks(this.fileSinkFactory.GetObsoleteFileSinks(this.retainedFileCountLimit), this.filePathDirectory);
                }

                if (this.currentSink != null)
                {
                    this.currentSink.Emit(logEvent);
                }
            }
        }