示例#1
0
        public void Log_ConfiguredConditionalLogLevelMapping_LogLevelNotChanged()
        {
            var logLevels = new LogLevelDictionary
            {
                {
                    CoreLogEvents.FailedToAcquireDistributedLock.EventId,
                    (exception, originalLogLevel, _) =>
                    {
                        if (exception is InvalidCastException)
                        {
                            return(LogLevel.Error);
                        }

                        return(originalLogLevel);
                    }
                }
            };
            var logger             = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Debug);
            var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels);
            var silverbackLogger   = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger);

            silverbackLogger.LogFailedToAcquireLock(
                new DistributedLockSettings("name", "id"),
                new InvalidOperationException());

            logger.Received(
                LogLevel.Debug,
                typeof(InvalidOperationException),
                "Failed to acquire lock name (id).");
        }
示例#2
0
        public void Log_ConfiguredMessageBasedLogLevelMapping_LogLevelChanged()
        {
            var logLevels = new LogLevelDictionary
            {
                {
                    CoreLogEvents.DistributedLockAcquired.EventId,
                    (_, originalLogLevel, message) =>
                    {
                        if (message.Value == "Acquired lock name (id).")
                        {
                            return(LogLevel.Error);
                        }

                        return(originalLogLevel);
                    }
                }
            };
            var logger             = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information);
            var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels);
            var silverbackLogger   = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger);

            silverbackLogger.LogLockAcquired(new DistributedLockSettings("name", "id"));

            logger.Received(LogLevel.Error, null, "Acquired lock name (id).");
        }
示例#3
0
        public CoreLoggerExtensionsTests()
        {
            var logLevels = new LogLevelDictionary();

            _logger = new LoggerSubstitute <CoreLoggerExtensionsTests>(LogLevel.Trace);
            var mappedLevelsLogger = new MappedLevelsLogger <CoreLoggerExtensionsTests>(_logger, logLevels);

            _silverbackLogger = new SilverbackLogger <CoreLoggerExtensionsTests>(mappedLevelsLogger);
        }
示例#4
0
        public void Log_EmptyLogLevelMapping_LogLevelNotChanged()
        {
            var logLevels          = new LogLevelDictionary();
            var logger             = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information);
            var mappedLevelsLogger =
                new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels);
            var silverbackLogger = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger);

            silverbackLogger.LogLockAcquired(new DistributedLockSettings("name", "id"));

            logger.Received(LogLevel.Information, null, "Acquired lock name (id).");
        }
示例#5
0
        public void Log_EventIdNotConfigured_LogLevelNotChanged()
        {
            var logLevels = new LogLevelDictionary
            {
                { CoreLogEvents.BackgroundServiceStarting.EventId, (_, _, _) => LogLevel.Error }
            };
            var logger             = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information);
            var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels);
            var silverbackLogger   = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger);

            silverbackLogger.LogLockAcquired(new DistributedLockSettings("name", "id"));

            logger.Received(LogLevel.Information, null, "Acquired lock name (id).");
        }
示例#6
0
        public void IsEnabled_ConfiguredLogLevelMapping_CheckedAccordingToNewLevel()
        {
            var logger   = new LoggerSubstitute <SilverbackLoggerTests>(LogLevel.Information);
            var logEvent = CoreLogEvents.AcquiringDistributedLock;

            logger.IsEnabled(logEvent.Level).Should().BeTrue();

            var logLevels = new LogLevelDictionary
            {
                { logEvent.EventId, (_, _, _) => LogLevel.Trace }
            };
            var mappedLevelsLogger = new MappedLevelsLogger <SilverbackLoggerTests>(logger, logLevels);
            var silverbackLogger   = new SilverbackLogger <SilverbackLoggerTests>(mappedLevelsLogger);

            var result = silverbackLogger.IsEnabled(logEvent);

            result.Should().BeFalse();
        }