public void accept_entries_that_got_an_exception()
        {
            var sut = new ExceptionsOnly();
            var entry = new LogEntry(LogLevel.Trace, "kkjlsdfkl", new Exception());

            var actual = sut.IsSatisfiedBy(entry);

            actual.Should().BeTrue();
        }
        public void reject_entry_without_exception()
        {
            var sut = new ExceptionsOnly();
            var entry = new LogEntry(LogLevel.Trace, "kkjlsdfkl", null);

            var actual = sut.IsSatisfiedBy(entry);

            actual.Should().BeFalse();
        }
        public void higher_level_is_inclusive()
        {
            var sut = new LogLevelFilter();
            sut.MaxLevel = LogLevel.Warning;
            var entry = new LogEntry(LogLevel.Warning, "kksdl", null);

            var actual = sut.IsSatisfiedBy(entry);

            actual.Should().BeTrue();
        }
        public void higher_level_rejects_those_above()
        {
            var sut = new LogLevelFilter();
            sut.MaxLevel = LogLevel.Info;
            var entry = new LogEntry(LogLevel.Warning, "kksdl", null);

            var actual = sut.IsSatisfiedBy(entry);

            actual.Should().BeFalse();
        }
        public void lower_level_is_accepting_above_ones()
        {
            var sut = new LogLevelFilter();
            sut.MinLevel = LogLevel.Info;
            var entry = new LogEntry(LogLevel.Warning, "kksdl", null);

            var actual = sut.IsSatisfiedBy(entry);

            actual.Should().BeTrue();
        }
        public void lower_level_rejects_those_under()
        {
            var sut = new LogLevelFilter();
            sut.MinLevel = LogLevel.Warning;
            var entry = new LogEntry(LogLevel.Info, "kksdl", null);

            var actual = sut.IsSatisfiedBy(entry);

            actual.Should().BeFalse();
        }
Esempio n. 7
0
        private void WriteEntry(LogLevel level, string message, Exception exception)
        {
            // find any filter that says no to logging
            if (_filters.Any(filter => !filter.CanLog(_loggedType, level)))
            {
                Console.WriteLine("Filter blocks");
                return;
            }

            if (!_discoveredFrames)
            {
                var trace = new StackTrace();
                FindCorrectFrame(trace);
                _discoveredFrames = true;
            }

            var frame = new StackFrame(_skipStackFrames);

            var userName = Thread.CurrentPrincipal.Identity.Name;
            if (string.IsNullOrEmpty(userName))
                userName = Environment.UserName;

            var entry = new LogEntry
                {
                    CreatedAt = DateTime.Now,
                    Exception = exception,
                    LogLevel = level,
                    LoggedType = _loggedType,
                    Message = message,
                    MethodName = frame.GetMethod().Name,
                    ThreadId = Thread.CurrentThread.ManagedThreadId,
                    UserName = userName
                };

            foreach (var target in _targets)
            {
                target.Enqueue(entry);
            }
        }
Esempio n. 8
0
 public override void Write(LogEntry entry)
 {
     Entries.Add(entry);
 }
        public void higher_level_is_accepting_below_ones()
        {
            var sut = new LogLevelFilter();
            sut.MaxLevel = LogLevel.Info;
            var entry = new LogEntry(LogLevel.Debug, "kksdl", null);

            var actual = sut.IsSatisfiedBy(entry);

            actual.Should().BeTrue();
        }
Esempio n. 10
0
        private void WriteEntry(LogLevel level, string message, Exception exception)
        {
            Contract.Requires<ArgumentNullException>(!String.IsNullOrEmpty(message));

            // find any filter that says no to logging
            Contract.Assume(_filters != null);
            if (_filters.Any(filter => !filter.CanLog(_loggedType, level)))
            {
                Console.WriteLine("Filter blocks");
                return;
            }

            StackFrame[] frames = new StackTrace(2).GetFrames();
            if (frames != null)
                frames = frames.Take(5).ToArray();

            string userName = Thread.CurrentPrincipal.Identity.Name;
            if (string.IsNullOrEmpty(userName))
                userName = Environment.UserName;

            var threadId = Thread.CurrentThread.ManagedThreadId;
            if (threadId<= 0)
                throw new InvalidOperationException("Expected to get a valid thread id.");

            Contract.Assume(_loggedType != null);
            var entry = new LogEntry(_loggedType, level, DateTime.Now, threadId,
                                     userName, message) {Exception = exception, StackFrames = frames};

            foreach (var target in _targets)
            {
                target.Enqueue(entry);
            }
        }