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"); }
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); }
public void ShouldPushErrorToSubscriber() { var log = new PubSubLogger(); var target = Substitute.For<ILogger>(); log.RegisterSubscriber(target); log.Error("LOL"); target.Received().Error("LOL"); }
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); }
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); }
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"); }