private void WriteToFile(LogEvent logEvent)
        {
            lock (_syncRoot)
            {
                if (_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();
                }

                _currentSink?.Emit(logEvent);
            }
        }
 public void Dispose()
 {
     lock (_syncRoot)
     {
         if (_disposed || _currentSink == null)
         {
             return;
         }
         _currentSink.Dispose();
         _currentSink = null;
         _disposed    = true;
         _cancelToken.Cancel();
     }
 }
        public SizeRollingFileSink(string pathFormat, ITextFormatter formatter, long fileSizeLimitBytes,
                                   TimeSpan?retainedFileDurationLimit, Encoding encoding = null)
        {
            _roller                    = new TemplatedPathRoller(pathFormat);
            _formatter                 = formatter;
            _fileSizeLimitBytes        = fileSizeLimitBytes;
            _encoding                  = encoding;
            _retainedFileDurationLimit = retainedFileDurationLimit;
            _currentSink               = GetLatestSink();

            if (AsyncOptions.SupportAsync)
            {
                _queue = new BlockingCollection <LogEvent>(AsyncOptions.BufferSize);
                Task.Run((Action)ProcessQueue, _cancelToken.Token);
            }
        }