public void Dispose()
 {
     if (!LogRecordCache.IsEmpty)
     {
         LogRecordCache.Flush(_writer);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DLoggerProvider"/> class
        /// </summary>
        /// <param name="settings"><see cref="ILoggerSettings"/> implementation instance</param>
        /// <param name="writer"><see cref="ILogWriter"/> implementation instance</param>
        /// <exception cref="ArgumentNullException">If the passed <see cref="ILoggerSettings"/> instance is null</exception>
        public DLoggerProvider(ILoggerSettings settings, ILogWriter writer)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _settings = settings;
            _writer   = writer;
            LogRecordCache.SetCapacity(_settings.BulkWriteCacheSize);

            _settings.ChangeToken?.RegisterChangeCallback(OnConfigurationReload, null);
        }
        private void OnConfigurationReload(object state)
        {
            // Creating a new settings object, because the old one is probably holding on to an old change token.
            _settings = _settings.Reload();

            if (!LogRecordCache.IsEmpty)
            {
                LogRecordCache.Flush(_writer);
            }

            LogRecordCache.SetCapacity(_settings.BulkWriteCacheSize);

            foreach (var logger in _loggers.Values)
            {
                logger.Filter   = GetFilter(logger.Category);
                logger.Settings = _settings;
            }

            // The token will change each time it reloads, so we need to register again.
            _settings?.ChangeToken?.RegisterChangeCallback(OnConfigurationReload, null);
        }