Inheritance: ILogEventSink, IDisposable
        private void WriteToFile(LogEvent logEvent)
        {
            lock (this.syncRoot)
            {
                if (this.disposed)
                {
                    throw new ObjectDisposedException(ThisObjectName, "The rolling file sink has been disposed");
                }

                var resetSequence = currentSink.LogFile.Date.Date != DateTime.UtcNow.Date;

                if (currentSink.EnableLevelLogging && currentSink.ActiveLogLevel != logEvent.Level)
                {
                    currentSink = NextSizeLimitedFileSink(resetSequence, logEvent.Level);
                }

                if (currentSink.SizeLimitReached || resetSequence)
                {
                    currentSink = NextSizeLimitedFileSink(resetSequence, logEvent.Level);
                    ApplyRetentionPolicy(roller.LogFileDirectory);
                }

                if (this.currentSink != null)
                {
                    this.currentSink.Emit(logEvent);
                }
            }
        }
        /// <summary>
        /// Emits a log event to this sink
        /// </summary>
        /// <param name="logEvent">The <see cref="LogEvent"/> to emit</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ObjectDisposedException"></exception>
        public void Emit(LogEvent logEvent)
        {

            if (logEvent == null)
            {
                throw new ArgumentNullException("logEvent");
            }

            lock (this.syncRoot)
            {
                if (this.disposed)
                {
                    throw new ObjectDisposedException(ThisObjectName, "The rolling file sink has been disposed");
                }

                var resetSequence = currentSink.LogFile.Date.Date != DateTime.UtcNow.Date;
                if (currentSink.SizeLimitReached || resetSequence)
                {
                    currentSink = NextSizeLimitedFileSink(resetSequence);
                    ApplyRetentionPolicy(roller.LogFileDirectory);
                }

                if (this.currentSink != null)
                {
                    this.currentSink.Emit(logEvent);
                }
            }
        }
        public SizeRollingFileSink(string pathFormat, ITextFormatter formatter, long fileSizeLimitBytes,
            TimeSpan? retainedFileDurationLimit, Encoding encoding = null)
        {
            roller = new TemplatedPathRoller(pathFormat);

            this.formatter = formatter;
            this.fileSizeLimitBytes = fileSizeLimitBytes;
            this.encoding = encoding;
            this.retainedFileDurationLimit = retainedFileDurationLimit;
            this.currentSink = GetLatestSink();
        }
 public void Dispose()
 {
     lock (this.syncRoot)
     {
         if (!disposed && currentSink != null)
         {
             currentSink.Dispose();
             currentSink = null;
             disposed = true;
         }
     }
 }
        public SizeRollingFileSink(string pathFormat, ITextFormatter formatter, long fileSizeLimitBytes,
            TimeSpan? retainedFileDurationLimit, Encoding encoding = null)
        {
            roller = new TemplatedPathRoller(pathFormat);

            this.formatter = formatter;
            this.fileSizeLimitBytes = fileSizeLimitBytes;
            this.encoding = encoding;
            this.retainedFileDurationLimit = retainedFileDurationLimit;
            this.currentSink = GetLatestSink();

            if (AsyncOptions.SupportAsync)
            {
                this.queue = new BlockingCollection<LogEvent>(AsyncOptions.BufferSize);
                Task.Run((Action)ProcessQueue, cancelToken.Token);
            }
        }
 public void Dispose()
 {
     lock (this.syncRoot)
     {
         if (!disposed && currentSink != null)
         {
             currentSink.Dispose();
             currentSink = null;
             disposed = true;
             cancelToken.Cancel();
         }
     }
 }