예제 #1
0
		public void ShouldPushInfoToSubscribers()
		{
			var log = new PubSubLogger();
			var target = Substitute.For<ILogger>();
			var target2 = Substitute.For<ILogger>();

			log.RegisterSubscriber(target);
			log.RegisterSubscriber(target2);

			log.Info("LOL");

			target.Received().Info("LOL");
			target2.Received().Info("LOL");
		}
예제 #2
0
		public LoggingContext(ILogger logger, IConfiguration configuration)
		{
			_logger = logger;
			_eventSource = configuration.Resolve<ILogger>() as PubSubLogger;

			if(_eventSource == null) throw new InvalidOperationException("You can only use logger contexts with PubSubLogger registered as the ILogger dependency.");

			_eventSource.RegisterSubscriber(_logger);
		}
예제 #3
0
		public void ShouldPushErrorToSubscriber()
		{
			var log = new PubSubLogger();
			var target = Substitute.For<ILogger>();

			log.RegisterSubscriber(target);

			log.Error("LOL");

			target.Received().Error("LOL");
		}
예제 #4
0
        public LoggingContext(ILogger logger, IConfiguration configuration)
        {
            _logger      = logger;
            _eventSource = configuration.Resolve <ILogger>() as PubSubLogger;

            if (_eventSource == null)
            {
                throw new InvalidOperationException("You can only use logger contexts with PubSubLogger registered as the ILogger dependency.");
            }

            _eventSource.RegisterSubscriber(_logger);
        }
예제 #5
0
		public void ShouldPushExceptionToSubscriber()
		{
			var log = new PubSubLogger();
			var target = Substitute.For<ILogger>();
			var exception = new Exception();

			log.RegisterSubscriber(target);

			log.Error(exception);

			target.Received().Error(exception);
		}
예제 #6
0
		public void ShouldNotPushInfoToSubscriber_WhenTransactionInScope()
		{
			var log = new PubSubLogger();
			var target = Substitute.For<ILogger>();

			log.RegisterSubscriber(target);

			using (new LogTransaction(log))
			{
				log.Info("LOL");
				target.DidNotReceive().Info("LOL");
			}

			target.Received().Info("LOL");
		}