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

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

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

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

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

            _changes.Should().Equal(LogFileSection.Reset,
                                    new LogFileSection(0, 1),
                                    new LogFileSection(1, 1),
                                    new LogFileSection(2, 1));
        }
예제 #2
0
        public void TestOneModification4()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.StartTimestamp).Should().NotHaveValue("because the source doesn't exist (yet)");

            var timestamp = new DateTime(2017, 3, 15, 22, 40, 0);

            _lines.Add(new LogLine());
            _source.Setup(x => x.GetValues(It.IsAny <ILogFileProperties>()))
            .Callback((ILogFileProperties properties) =>
            {
                properties.SetValue(LogFileProperties.StartTimestamp, timestamp);
            });
            logFile.GetValue(LogFileProperties.StartTimestamp).Should().NotHaveValue("because the change shouldn't have been applied yet");

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            logFile.GetValue(LogFileProperties.StartTimestamp).Should().NotHaveValue("because the change shouldn't have been applied yet");

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.StartTimestamp).Should().Be(timestamp, "because the change should have been applied by now");
        }
예제 #3
0
        public void TestOneModification3()
        {
            _source.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.SourceDoesNotExist);
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist, "because the source doesn't exist (yet)");

            _lines.Add(new LogLine());
            _source.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.None);
            _source.Setup(x => x.GetValues(It.IsAny <ILogFileProperties>()))
            .Callback((ILogFileProperties properties) =>
            {
                properties.SetValue(LogFileProperties.EmptyReason, ErrorFlags.None);
            });

            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist, "because the change shouldn't have been applied yet");

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist, "because the change shouldn't have been applied yet");

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.None, "because the change should have been applied by now");
        }
예제 #4
0
        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");
            }
        }
예제 #5
0
        public void TestMultilineNoLogLevels()
        {
            using (var source0 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.MultilineNoLogLevel1, new CustomTimestampParser()))
                using (var source1 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.MultilineNoLogLevel2, new CustomTimestampParser()))
                    using (var multi0 = new MultiLineLogFile(_scheduler, source0, TimeSpan.Zero))
                        using (var multi1 = new MultiLineLogFile(_scheduler, source1, TimeSpan.Zero))
                            using (var merged = new MergedLogFile(_scheduler, TimeSpan.Zero, multi0, multi1))
                            {
                                merged.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(10)).BeTrue();
                                var entries = merged.GetEntries(new LogFileSection(0, 11),
                                                                LogFileColumns.Timestamp,
                                                                LogFileColumns.LogEntryIndex,
                                                                LogFileColumns.LineNumber,
                                                                LogFileColumns.RawContent,
                                                                LogFileColumns.OriginalDataSourceName);

                                var line = entries[0];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 176));
                                line.RawContent.Should().Be("18/03/2019 14:09:54:176    1 Information BTPVM3372 05:30:00 6060");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(0));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log2.txt");

                                line = entries[1];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 177));
                                line.RawContent.Should()
                                .Be("2019-03-18 14:09:54:177 1 00:00:00:0000000 Information Initialize Globals");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(1));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log1.txt");

                                line = entries[2];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 177));
                                line.RawContent.Should().Be("Started BTPVM3372 05:30:00 6060");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(1));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log1.txt");

                                line = entries[3];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 178));
                                line.RawContent.Should().Be("18/03/2019 14:09:54:178    1 Information   Loading preferences Started");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(2));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log2.txt");

                                line = entries[4];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 178));
                                line.RawContent.Should().Be("BTPVM3372 05:30:00 6060");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(2));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log2.txt");

                                line = entries[5];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 313));
                                line.RawContent.Should().Be("2019-03-18 14:09:54:313 1 00:00:00:0000000 Information   Loading");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(3));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log1.txt");

                                line = entries[6];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 313));
                                line.RawContent.Should().Be("preferences Started BTPVM3372 05:30:00 6060");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(3));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log1.txt");

                                line = entries[7];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 550));
                                line.RawContent.Should()
                                .Be("18/03/2019 14:09:54:550    1 Information    RMClientURL: BTPVM3372 05:30:00");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(4));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log2.txt");

                                line = entries[8];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 550));
                                line.RawContent.Should().Be("6060");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(4));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log2.txt");

                                line = entries[9];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 551));
                                line.RawContent.Should().Be("2019-03-18 14:09:54:551 1 00:00:00:0000000 Information    RMClientURL:");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(5));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log1.txt");

                                line = entries[10];
                                line.Timestamp.Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 551));
                                line.RawContent.Should().Be("BTPVM3372 05:30:00 6060");
                                line.LogEntryIndex.Should().Be(new LogEntryIndex(5));
                                line.GetValue(LogFileColumns.OriginalDataSourceName).Should().Be(@"TestData\Multiline\Log1.txt");
                            }
        }