public ServiceLevelAgreementMonitor(IServiceLevelAgreementProvider slaProvider, LoggingConfiguration slaConfiguration)
        {
            _slaProvider = slaProvider;

            logSlaBreach = slaConfiguration.ConfigureLoggingAction(Logger, slaConfiguration.LoggingLevelWhenSLAIsBreached);
            logSlaMet = slaConfiguration.ConfigureLoggingAction(Logger, slaConfiguration.LoggingLevelWhenSLAIsMet);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a SlaProvessor that uses given <c>provider</c> SlaProvider to determine which messages should be monitored.
        /// The <c>quotaPerMessageType</c> determines how many request messages of given type would be tracked at the same time (<see cref="QuotaPerMessageType"/> for details).
        /// </summary>
        /// <param name="provider">SlaProvider instance</param>
        /// <param name="quotaPerMessageType">The maximum number of request messages of given type that can be tracked at the same time.</param>
        /// <param name="loggingConfiguration">Specifies the log level for when SLA is met/breached</param>
        /// <param name="timeoutValidationSchedulerFactory">Timeout scheduler factory</param>
        protected internal SlaProcessor(SlaProvider provider, int quotaPerMessageType, LoggingConfiguration loggingConfiguration, Func<ISlaProcessor, IDisposable> timeoutValidationSchedulerFactory)
        {
            _provider = provider;
            QuotaPerMessageType = quotaPerMessageType;

            _logSlaBreach = loggingConfiguration.ConfigureLoggingAction(_logger, loggingConfiguration.LoggingLevelWhenSLAIsBreached);
            _logSlaMet = loggingConfiguration.ConfigureLoggingAction(_logger, loggingConfiguration.LoggingLevelWhenSLAIsMet);
            _timeoutValidationScheduler = timeoutValidationSchedulerFactory.Invoke(this);
        }
        public void ServiceLevelAgreementMonitor_Should_be_able_to_configure_the_logging_level_when_sla_is_met(Level level)
        {
            var slaProvider = new Mock<IServiceLevelAgreementProvider>();
            SetupSLAWayIntoTheFuture(slaProvider);
            var loggingConfiguration = new LoggingConfiguration(loggingLevelWhenSlaIsMet: level, loggingLevelWhenSlaIsBreached: Level.Off);

            var monitor = new ServiceLevelAgreementMonitor(slaProvider.Object, loggingConfiguration);
            var expectedSlaType = typeof(SynchronousSLAMonitorTests);

            var mockIntercept = new Mock<IInvocation>();
            mockIntercept.Setup(x => x.TargetType).Returns(expectedSlaType);

            monitor.Intercept(mockIntercept.Object);

            var appender = GetAppender();

            AssertLoggingEvent(appender.Events, level);
        }
        public void ServiceLevelAgreementMonitor_Should_be_able_to_configure_the_breach_logging_level(Level level)
        {
            var slaProvider = new Mock<IServiceLevelAgreementProvider>();
            SetupSLAOfZero(slaProvider);
            var loggingConfiguration = new LoggingConfiguration(loggingLevelWhenSlaIsMet: Level.Off, loggingLevelWhenSlaIsBreached: level);

            var monitor = new ServiceLevelAgreementMonitor(slaProvider.Object, loggingConfiguration);
            var expectedSlaType = typeof(SynchronousSLAMonitorTests);

            var mockIntercept = new Mock<IInvocation>();
            mockIntercept.Setup(x => x.Proceed()).Callback(() => Thread.Sleep(5));

            mockIntercept.Setup(x => x.TargetType).Returns(expectedSlaType);

            monitor.Intercept(mockIntercept.Object);

            var appender = GetAppender();

            AssertLoggingEvent(appender.Events, level);
        }
 /// <summary>
 /// Overrides LoggingConfiguration for SlaProcessor.
 /// </summary>
 public SlaProcessorBuilder WithLoggingConfiguration(LoggingConfiguration loggingConfiguration)
 {
     _loggingConfiguration = loggingConfiguration;
     return this;
 }