Exemplo n.º 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();
        }
Exemplo n.º 2
0
        private LogManager(IEnumerable <IAppender> appenders, int size, Level level = Level.Finest)
        {
            _level    = level;
            _encoding = Encoding.Default;
            _queue    = new ConcurrentQueue <LogEvent>(new FakeCollection(size));
            var bufferSegmentProvider = new BufferSegmentProvider(size * 128, 128);

            _pool = new ObjectPool <LogEvent>(() => new LogEvent(bufferSegmentProvider.GetSegment()), size);

            foreach (var appender in appenders)
            {
                appender.SetEncoding(_encoding);
            }

            _appenders = new List <IAppender>(appenders);

            _writeTask = Task.Run(() => WriteToAppenders());
        }
Exemplo n.º 3
0
        internal LogManager(IConfigurationResolver configResolver, int logEventQueueSize = 1024, int logEventBufferSize = 128)
        {
            _configResolver = configResolver;

            _loggers = new ConcurrentQueue <Log>();
            _queue   = new ConcurrentQueue <IInternalLogEvent>(new ConcurrentQueueCapacityInitializer(logEventQueueSize));

            _bufferSegmentProvider = new BufferSegmentProvider(logEventQueueSize * logEventBufferSize, logEventBufferSize);
            _pool = new ObjectPool <IInternalLogEvent>(logEventQueueSize, () => new LogEvent(_bufferSegmentProvider.GetSegment()));

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

            _isRunning = true;
            _writeTask = Task.Factory.StartNew(WriteToAppenders, TaskCreationOptions.LongRunning);
        }