public void AnExceptionThrownByASinkIsNotPropagated()
        {
            var thrown = false;

            var s = new SafeAggregateSink(new[] { new DelegatingSink(le => {
                thrown = true;
                throw new Exception("No go, pal.");
            }) });

            s.Emit(Some.InformationEvent());

            Assert.IsTrue(thrown);
        }
        public void WhenASinkThrowsOtherSinksAreStillInvoked()
        {
            bool called1 = false, called2 = false;

            var s = new SafeAggregateSink(new[] {
                new DelegatingSink(le => called1 = true),
                new DelegatingSink(le => { throw new Exception("No go, pal."); }),
                new DelegatingSink(le => called2 = true)
            });

            s.Emit(Some.InformationEvent());

            Assert.IsTrue(called1 && called2);
        }
示例#3
0
        /// <summary>
        /// Create a logger using the configured sinks, enrichers and minimum level.
        /// </summary>
        /// <returns>The logger.</returns>
        /// <remarks>To free resources held by sinks ahead of program shutdown,
        /// the returned logger may be cast to <see cref="IDisposable"/> and
        /// disposed.</remarks>
        public ILogger CreateLogger()
        {
            Action dispose = () =>
            {
                foreach (var disp in _logEventSinks.OfType<IDisposable>())
                    disp.Dispose();
            };

            var sink = new SafeAggregateSink(_logEventSinks);

            if (_filters.Any())
                sink = new SafeAggregateSink(new[] { new FilteringSink(sink, _filters) });

            var processor = new MessageTemplateProcessor();

            return new Logger(processor, _minimumLevel, sink, _enrichers, dispose);
        }