Example #1
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);
		}
Example #2
0
		public void ShouldPushErrorToSubscriber()
		{
			var log = new PubSubLogger();
			var target = Substitute.For<ILogger>();

			log.RegisterSubscriber(target);

			log.Error("LOL");

			target.Received().Error("LOL");
		}
Example #3
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);
        }
Example #4
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);
		}
Example #5
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");
		}
Example #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");
		}