Example #1
0
        public void TestManyEntries2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "A", LevelFlags.Debug));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(1, 1, "B", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(2, 2, "C", LevelFlags.Warning));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(2, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(3, 3, "D", LevelFlags.Error));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(3, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(4, 4, "E", LevelFlags.Fatal));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(4, 1));
            _taskScheduler.RunOnce();

            logFile.Count.Should().Be(5);
            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "A", LevelFlags.Debug));
            logFile.GetLine(1).Should().Be(new LogLine(1, 1, "B", LevelFlags.Info));
            logFile.GetLine(2).Should().Be(new LogLine(2, 2, "C", LevelFlags.Warning));
            logFile.GetLine(3).Should().Be(new LogLine(3, 3, "D", LevelFlags.Error));
            logFile.GetLine(4).Should().Be(new LogLine(4, 4, "E", LevelFlags.Fatal));
        }
Example #2
0
        public void TestOneEntry1()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            var timestamp = new DateTime(2017, 3, 15, 21, 52, 0);

            _lines.Add(new LogLine(0, 0, "INFO: hello", LevelFlags.Info, timestamp));
            _lines.Add(new LogLine(1, 1, "world!", LevelFlags.None, timestamp));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 2));

            _taskScheduler.RunOnce();

            logFile.Count.Should().Be(2);
            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "INFO: hello", LevelFlags.Info, timestamp));
            logFile.GetLine(1).Should().Be(new LogLine(1, 0, "world!", LevelFlags.Info, timestamp));
        }
Example #3
0
        public void TestOneLine2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            logFile.AddListener(_listener.Object, TimeSpan.Zero, 10);

            _lines.Add(new LogLine(0, 0, "INFO: Hello ", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);
            _changes.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, 1) });

            _lines[0] = new LogLine(0, 0, "Hello World!", LevelFlags.None);
            logFile.OnLogFileModified(_source.Object, LogFileSection.Invalidate(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(0);

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);
            _changes.Should().Equal(new object[]
            {
                LogFileSection.Reset,
                new LogFileSection(0, 1),
                LogFileSection.Invalidate(0, 1),
                new LogFileSection(0, 1)
            });

            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "Hello World!", LevelFlags.None));
        }
Example #4
0
        public void TestOneLine3()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "Hello World!", LevelFlags.None));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);
            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "Hello World!", LevelFlags.None));
        }
        public void TestMultilineNoLevel3()
        {
            using (var source = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.MultilineNoLogLevel1, new CustomTimestampParser()))
                using (var multi = new MultiLineLogFile(_scheduler, source, TimeSpan.Zero))
                {
                    multi.Property(x => x.Count).ShouldAfter(TimeSpan.FromMinutes(5)).Be(6);

                    var line = multi.GetLine(0);
                    line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 177));
                    line.LogEntryIndex.Should().Be(0);
                    line.LineIndex.Should().Be(0);
                    line.Message.Should().Be("2019-03-18 14:09:54:177 1 00:00:00:0000000 Information Initialize Globals");

                    line = multi.GetLine(1);
                    line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 177));
                    line.LogEntryIndex.Should().Be(0);
                    line.LineIndex.Should().Be(1);
                    line.Message.Should().Be("Started BTPVM3372 05:30:00 6060");

                    line = multi.GetLine(2);
                    line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 313));
                    line.LogEntryIndex.Should().Be(1);
                    line.LineIndex.Should().Be(2);
                    line.Message.Should().Be("2019-03-18 14:09:54:313 1 00:00:00:0000000 Information   Loading");

                    line = multi.GetLine(3);
                    line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 313));
                    line.LogEntryIndex.Should().Be(1);
                    line.LineIndex.Should().Be(3);
                    line.Message.Should().Be("preferences Started BTPVM3372 05:30:00 6060");

                    line = multi.GetLine(4);
                    line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 551));
                    line.LogEntryIndex.Should().Be(2);
                    line.LineIndex.Should().Be(4);
                    line.Message.Should().Be("2019-03-18 14:09:54:551 1 00:00:00:0000000 Information    RMClientURL:");

                    line = multi.GetLine(5);
                    line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 551));
                    line.LogEntryIndex.Should().Be(2);
                    line.LineIndex.Should().Be(5);
                    line.Message.Should().Be("BTPVM3372 05:30:00 6060");
                }
        }
        public void TestTimestampsAndMixedInfos()
        {
            var logFile = new InMemoryLogFile();

            using (var multiLine = new MultiLineLogFile(_taskScheduler, logFile, TimeSpan.Zero))
            {
                logFile.AddRange(new[]
                {
                    new LogEntry2 {
                        Timestamp = new DateTime(2017, 3, 24, 11, 45, 19, 195), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-19.195339; 0; 0;  0; 108;  0; 124;   1;INFO; ; ; ; ; ; 0; Some interesting message"
                    },
                    new LogEntry2 {
                        Timestamp = new DateTime(2017, 3, 24, 11, 45, 19, 751), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-19.751428; 0; 0;  0; 129;  0; 145;   1;INFO; ; ; ; ; ; 0; Very interesting stuff"
                    },
                    new LogEntry2 {
                        Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 708), LogLevel = LevelFlags.Other, RawContent = "2017-03-24 11-45-21.708485; 0; 0;  0; 109;  0; 125;   1;PB_CREATE; ; ; 109; 2;"
                    }
                });

                _taskScheduler.RunOnce();
                multiLine.Count.Should().Be(3);

                var line0 = multiLine.GetLine(0);
                line0.OriginalLineIndex.Should().Be(0);
                line0.LineIndex.Should().Be(0);
                line0.LogEntryIndex.Should().Be(0, "because every line is an individual log entry");

                var line1 = multiLine.GetLine(1);
                line1.OriginalLineIndex.Should().Be(1);
                line1.LineIndex.Should().Be(1);
                line1.LogEntryIndex.Should().Be(1, "because every line is an individual log entry");

                var line2 = multiLine.GetLine(2);
                line2.OriginalLineIndex.Should().Be(2);
                line2.LineIndex.Should().Be(2);
                line2.LogEntryIndex.Should().Be(2, "because every line is an individual log entry");


                logFile.RemoveFrom(new LogLineIndex(2));
                logFile.AddRange(new []
                {
                    new LogEntry2 {
                        Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 708), LogLevel = LevelFlags.Other, RawContent = "2017-03-24 11-45-21.708485; 0; 0;  0; 109;  0; 125;   1;PB_CREATE; ; ; 109; 2; Sooo interesting"
                    },
                    new LogEntry2 {
                        Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 708), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-21.708599; 0; 0;  0; 108;  0; 124;   1;INFO; ; ; ; ; ; 0; Go on!"
                    },
                    new LogEntry2 {
                        Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 811), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-21.811838; 0; 0;  0; 108;  0; 124;   1;INFO; ; ; ; ; ; 0; done."
                    }
                });
                _taskScheduler.RunOnce();
                multiLine.Count.Should().Be(5);

                line0 = multiLine.GetLine(0);
                line0.OriginalLineIndex.Should().Be(0);
                line0.LineIndex.Should().Be(0);
                line0.LogEntryIndex.Should().Be(0, "because every line is an individual log entry");

                line1 = multiLine.GetLine(1);
                line1.OriginalLineIndex.Should().Be(1);
                line1.LineIndex.Should().Be(1);
                line1.LogEntryIndex.Should().Be(1, "because every line is an individual log entry");

                line2 = multiLine.GetLine(2);
                line2.OriginalLineIndex.Should().Be(2);
                line2.LineIndex.Should().Be(2);
                line2.LogEntryIndex.Should().Be(2, "because every line is an individual log entry");

                var line3 = multiLine.GetLine(3);
                line3.OriginalLineIndex.Should().Be(3);
                line3.LineIndex.Should().Be(3);
                line3.LogEntryIndex.Should().Be(3, "because every line is an individual log entry");

                var line4 = multiLine.GetLine(4);
                line4.OriginalLineIndex.Should().Be(4);
                line4.LineIndex.Should().Be(4);
                line4.LogEntryIndex.Should().Be(4, "because every line is an individual log entry");
            }
        }