Ejemplo n.º 1
0
        public void LoggerMultipleLogTargetsSameLogLevelTest()
        {
            var logTarget1 = new TestLogTarget(LogLevel.Trace, null, null, null);
            var logTarget2 = new TestLogTarget(LogLevel.Trace, null, null, null);

            var logTargets = new List <LogTarget>
            {
                logTarget1,
                logTarget2
            };

            var logger = new Logger(logTargets, LogFrequency);


            this.LogTestMessages(logger);
            Thread.Sleep(SleepTime);


            foreach (TestLogTarget logTarget in logTargets)
            {
                Assert.IsTrue(logTarget.LogEntries.Count > 0);
                Assert.AreEqual(6, logTarget.LogEntries.Count);

                var logEntriesByLogLevel = this.GetLogEntriesByLogLevel(logTarget);

                Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Trace));
                Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Debug));
                Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Information));
                Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Warning));
                Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Error));
                Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Critical));
            }
        }
Ejemplo n.º 2
0
        public void LoggerLogLevelInformationTest()
        {
            var logTarget = new TestLogTarget(LogLevel.Information, null, null, null);

            var logTargets = new List <LogTarget>
            {
                logTarget
            };

            var logger = new Logger(logTargets, LogFrequency);

            this.LogTestMessages(logger);

            Thread.Sleep(SleepTime);


            Assert.IsTrue(logTarget.LogEntries.Count > 0);
            Assert.AreEqual(4, logTarget.LogEntries.Count);

            var logEntriesByLogLevel = this.GetLogEntriesByLogLevel(logTarget);

            Assert.IsFalse(logEntriesByLogLevel.ContainsKey(LogLevel.Trace));
            Assert.IsFalse(logEntriesByLogLevel.ContainsKey(LogLevel.Debug));
            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Information));
            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Warning));
            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Error));
            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Critical));
        }
Ejemplo n.º 3
0
        public void LoggerLogEntriesContainAllInformationTest()
        {
            var logTarget = new TestLogTarget(LogLevel.Trace, null, null, null);

            var logTargets = new List <LogTarget>
            {
                logTarget
            };

            var logger = new Logger(logTargets, LogFrequency);


            this.LogTestMessages(logger);
            Thread.Sleep(SleepTime);


            Assert.IsTrue(logTarget.LogEntries.Count > 0);
            Assert.AreEqual(6, logTarget.LogEntries.Count);

            var logEntriesByLogLevel = this.GetLogEntriesByLogLevel(logTarget);

            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Trace));
            Assert.AreEqual(LogLevel.Trace, logEntriesByLogLevel[LogLevel.Trace].LogLevel);
            Assert.AreEqual(SourceMemberName, logEntriesByLogLevel[LogLevel.Trace].SourceMemberName);
            Assert.AreEqual(SourceClassName, logEntriesByLogLevel[LogLevel.Trace].SourceClassName);
            Assert.AreEqual(TestMessageTrace, logEntriesByLogLevel[LogLevel.Trace].Message);

            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Debug));
            Assert.AreEqual(LogLevel.Debug, logEntriesByLogLevel[LogLevel.Debug].LogLevel);
            Assert.AreEqual(SourceMemberName, logEntriesByLogLevel[LogLevel.Debug].SourceMemberName);
            Assert.AreEqual(SourceClassName, logEntriesByLogLevel[LogLevel.Debug].SourceClassName);
            Assert.AreEqual(TestMessageDebug, logEntriesByLogLevel[LogLevel.Debug].Message);

            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Information));
            Assert.AreEqual(LogLevel.Information, logEntriesByLogLevel[LogLevel.Information].LogLevel);
            Assert.AreEqual(SourceMemberName, logEntriesByLogLevel[LogLevel.Information].SourceMemberName);
            Assert.AreEqual(SourceClassName, logEntriesByLogLevel[LogLevel.Information].SourceClassName);
            Assert.AreEqual(TestMessageInformation, logEntriesByLogLevel[LogLevel.Information].Message);

            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Warning));
            Assert.AreEqual(LogLevel.Warning, logEntriesByLogLevel[LogLevel.Warning].LogLevel);
            Assert.AreEqual(SourceMemberName, logEntriesByLogLevel[LogLevel.Warning].SourceMemberName);
            Assert.AreEqual(SourceClassName, logEntriesByLogLevel[LogLevel.Warning].SourceClassName);
            Assert.AreEqual(TestMessageWarning, logEntriesByLogLevel[LogLevel.Warning].Message);

            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Error));
            Assert.AreEqual(LogLevel.Error, logEntriesByLogLevel[LogLevel.Error].LogLevel);
            Assert.AreEqual(SourceMemberName, logEntriesByLogLevel[LogLevel.Error].SourceMemberName);
            Assert.AreEqual(SourceClassName, logEntriesByLogLevel[LogLevel.Error].SourceClassName);
            Assert.AreEqual(TestMessageError, logEntriesByLogLevel[LogLevel.Error].Message);

            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Critical));
            Assert.AreEqual(LogLevel.Critical, logEntriesByLogLevel[LogLevel.Critical].LogLevel);
            Assert.AreEqual(SourceMemberName, logEntriesByLogLevel[LogLevel.Critical].SourceMemberName);
            Assert.AreEqual(SourceClassName, logEntriesByLogLevel[LogLevel.Critical].SourceClassName);
            Assert.AreEqual(TestMessageCritical, logEntriesByLogLevel[LogLevel.Critical].Message);
        }
Ejemplo n.º 4
0
        private Dictionary <LogLevel, LogEntry> GetLogEntriesByLogLevel(TestLogTarget logTarget)
        {
            var logEntriesByLogLevel = new Dictionary <LogLevel, LogEntry>();

            foreach (var logEntry in logTarget.LogEntries)
            {
                logEntriesByLogLevel[logEntry.LogLevel] = logEntry;
            }

            return(logEntriesByLogLevel);
        }
Ejemplo n.º 5
0
        public void LoggerSameLogLevelInBothWhitelistAndBlacklistTest()
        {
            var logLevelBlacklist = new List <LogLevel>
            {
                LogLevel.Trace,
                LogLevel.Debug,
                LogLevel.Information,
                LogLevel.Warning,
                LogLevel.Error
            };

            var logLevelWhitelist = new List <LogLevel>
            {
                LogLevel.Trace,
                LogLevel.Debug,
                LogLevel.Information,
                LogLevel.Warning,
                LogLevel.Error
            };

            var logTarget = new TestLogTarget(LogLevel.Trace, logLevelBlacklist, logLevelWhitelist, null);

            var logTargets = new List <LogTarget>
            {
                logTarget
            };

            var logger = new Logger(logTargets, LogFrequency);


            this.LogTestMessages(logger);
            Thread.Sleep(SleepTime);

            Assert.AreEqual(1, logTarget.LogEntries.Count);

            var logEntriesByLogLevel = this.GetLogEntriesByLogLevel(logTarget);

            Assert.IsFalse(logEntriesByLogLevel.ContainsKey(LogLevel.Trace));
            Assert.IsFalse(logEntriesByLogLevel.ContainsKey(LogLevel.Debug));
            Assert.IsFalse(logEntriesByLogLevel.ContainsKey(LogLevel.Information));
            Assert.IsFalse(logEntriesByLogLevel.ContainsKey(LogLevel.Warning));
            Assert.IsFalse(logEntriesByLogLevel.ContainsKey(LogLevel.Error));
            Assert.IsTrue(logEntriesByLogLevel.ContainsKey(LogLevel.Critical));
        }
Ejemplo n.º 6
0
        public void LoggerLogTargetTerminationTest()
        {
            var logTarget = new TestLogTarget(LogLevel.Trace, null, null, DateTime.Now.AddMilliseconds(SleepTime * 2));

            var logTargets = new List <LogTarget>
            {
                logTarget
            };

            var logger = new Logger(logTargets, LogFrequency);


            this.LogTestMessages(logger);
            Thread.Sleep(SleepTime);
            this.LogTestMessages(logger);

            Assert.IsTrue(logTarget.LogEntries.Count > 0);
            Assert.AreEqual(6, logTarget.LogEntries.Count);
        }
Ejemplo n.º 7
0
        public void LoggerLogLevelNoneTest()
        {
            var logTarget = new TestLogTarget(LogLevel.None, null, null, null);

            var logTargets = new List <LogTarget>
            {
                logTarget
            };

            var logger = new Logger(logTargets, LogFrequency);


            this.LogTestMessages(logger);
            Thread.Sleep(SleepTime);


            Assert.IsTrue(logTarget.LogEntries.Count == 0);

            var logEntriesByLogLevel = this.GetLogEntriesByLogLevel(logTarget);

            Assert.IsTrue(logTarget.LogEntries.Count == 0);
        }