Exemple #1
0
        internal LogManager(IConfigurationResolver configResolver, ZeroLogInitializationConfig config)
        {
            config.Validate();

            _configResolver = configResolver;

            _queue = new ConcurrentQueue <IInternalLogEvent>(new ConcurrentQueueCapacityInitializer(config.LogEventQueueSize));

            _bufferSegmentProvider = new BufferSegmentProvider(config.LogEventQueueSize * config.LogEventBufferSize, config.LogEventBufferSize);
            _pool = new ObjectPool <IInternalLogEvent>(config.LogEventQueueSize, () => new LogEvent(_bufferSegmentProvider.GetSegment(), config.LogEventArgumentCapacity));

            configResolver.Initialize(_encoding);
            configResolver.Updated += () =>
            {
                foreach (var logger in _loggers.Values)
                {
                    logger.ResetConfiguration();
                }

                UpdateAppenders();
            };

            UpdateAppenders();

            _isRunning = true;

            _writeThread = new Thread(WriteThread)
            {
                Name = $"{nameof(ZeroLog)}.{nameof(WriteThread)}"
            };

            _writeThread.Start();
        }
Exemple #2
0
        public static ILogManager Initialize(IConfigurationResolver configResolver, [CanBeNull] ZeroLogInitializationConfig config = null)
        {
            if (_logManager != _noOpLogManager)
            {
                throw new ApplicationException("LogManager is already initialized");
            }

            _logManager = new LogManager(configResolver, config ?? new ZeroLogInitializationConfig());
            return(_logManager);
        }