Пример #1
0
        public void TestGetSection1()
        {
            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("yikes", true, LevelFlags.All)))
            {
                _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
                _entries.Add(new LogLine(1, 1, "Yikes", LevelFlags.Info));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2));

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue();

                var section = file.GetSection(new LogFileSection(0, 1));
                section.Should().NotBeNull();
                section.Length.Should().Be(1);
                section[0].LineIndex.Should().Be(0, "because the filtered log file only represents a file with one line, thus the only entry should have an index of 0, not 1, which is the original index");
                section[0].OriginalLineIndex.Should().Be(1, "because the given line is the second line in the source file");
                section[0].Message.Should().Be("Yikes");
                section[0].Level.Should().Be(LevelFlags.Info);

                var line = file.GetLine(0);
                line.LineIndex.Should().Be(0, "because the filtered log file only represents a file with one line, thus the only entry should have an index of 0, not 1, which is the original index");
                line.OriginalLineIndex.Should().Be(1, "because the given line is the second line in the source file");
                line.Message.Should().Be("Yikes");
                line.Level.Should().Be(LevelFlags.Info);
            }
        }
Пример #2
0
        public void TestFilter3()
        {
            const string fname = "TestFilter3.log";

            using (FileStream stream = File.OpenWrite(fname))
                using (var writer = new StreamWriter(stream))
                {
                    stream.SetLength(0);
                    writer.WriteLine("INFO - Test");
                }

            using (var file = new TextLogFile(_scheduler, fname))
            {
                file.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5));

                file.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5));

                using (FilteredLogFile filtered = file.AsFiltered(_scheduler, null, Filter.Create("e", LevelFlags.All), TimeSpan.Zero))
                {
                    var listener = new Mock <ILogFileListener>();
                    var sections = new List <LogFileSection>();
                    listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>()))
                    .Callback((ILogFile logFile, LogFileSection section) => sections.Add(section));
                    filtered.AddListener(listener.Object, TimeSpan.FromHours(1), 1000);

                    filtered.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5));
                    filtered.GetSection(new LogFileSection(0, filtered.Count)).Should().Equal(new[]
                    {
                        new LogLine(0, "INFO - Test", LevelFlags.Info)
                    });

                    using (var stream = new FileStream(fname, FileMode.Open, FileAccess.Write, FileShare.ReadWrite))
                    {
                        stream.SetLength(0);
                    }

                    filtered.Property(x => x.Count).ShouldEventually().Be(0, TimeSpan.FromSeconds(5));
                    filtered.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5));
                    sections.Should().EndWith(LogFileSection.Reset);
                }
            }
        }
Пример #3
0
        public void TestMultiLineLogEntry2()
        {
            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("yikes", true, LevelFlags.All)))
            {
                _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
                _entries.Add(new LogLine(1, 0, "Yikes", LevelFlags.None));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2));

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue();

                file.Count.Should().Be(2);
                file.GetSection(new LogFileSection(0, 2))
                .Should().Equal(new[]
                {
                    new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug),
                    new LogLine(1, 0, "Yikes", LevelFlags.None)
                });
            }
        }
Пример #4
0
        public void TestEntryLevelNone()
        {
            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("ello", true, LevelFlags.All)))
            {
                _entries.Add(new LogLine(0, "Hello world!", LevelFlags.None));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 1));

                _taskScheduler.RunOnce();

                file.EndOfSourceReached.Should().BeTrue();
                file.Count.Should().Be(1);
                var section = file.GetSection(new LogFileSection(0, 1));
                section.Should().HaveCount(1);
                section[0].LineIndex.Should().Be(0);
                section[0].OriginalLineIndex.Should().Be(0);
                section[0].LogEntryIndex.Should().Be(0);
                section[0].Message.Should().Be("Hello world!");
                section[0].Level.Should().Be(LevelFlags.None);
            }
        }
Пример #5
0
        public void TestFilter1()
        {
            using (var file = new TextLogFile(_scheduler, File20Mb))
            {
                file.Property(x => x.Count).ShouldEventually().Be(165342, TimeSpan.FromSeconds(5));

                using (FilteredLogFile filtered = file.AsFiltered(_scheduler, null, Filter.Create("info")))
                {
                    filtered.Property(x => x.Count).ShouldEventually().Be(5, TimeSpan.FromSeconds(5));
                    filtered.GetValue(LogFileProperties.StartTimestamp).Should().Be(new DateTime(2015, 10, 7, 19, 50, 58, 982));

                    LogLine[] section = filtered.GetSection(new LogFileSection(0, 5));
                    section.Should().Equal(new[]
                    {
                        new LogLine(0, 0,
                                    "2015-10-07 19:50:58,982 [8092, 1] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Silo Server starting, args (1): \"14056\", without custom type resolver",
                                    LevelFlags.Info,
                                    new DateTime(2015, 10, 7, 19, 50, 58, 982, DateTimeKind.Unspecified)),
                        new LogLine(1, 1,
                                    "2015-10-07 19:50:59,081 [8092, 1] INFO  SharpRemote.SocketRemotingEndPointServer (null) - EndPoint '<Unnamed>' listening on 0.0.0.0:49152",
                                    LevelFlags.Info,
                                    new DateTime(2015, 10, 7, 19, 50, 59, 081)),
                        new LogLine(2, 2,
                                    "2015-10-07 19:50:59,171 [8092, 6] INFO  SharpRemote.AbstractIPSocketRemotingEndPoint (null) - <Unnamed>: Connected to 127.0.0.1:10348",
                                    LevelFlags.Info,
                                    new DateTime(2015, 10, 7, 19, 50, 59, 171)),
                        new LogLine(3, 3,
                                    "2015-10-07 19:51:42,481 [8092, EndPoint '<Unnamed>' Socket Reading] INFO  SharpRemote.AbstractSocketRemotingEndPoint (null) - Disconnecting socket '<Unnamed>' from 127.0.0.1:10348: ReadFailure",
                                    LevelFlags.Info,
                                    new DateTime(2015, 10, 7, 19, 51, 42, 481)),
                        new LogLine(4, 4,
                                    "2015-10-07 19:51:42,483 [8092, 6] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Parent process terminated unexpectedly (exit code: -1), shutting down...",
                                    LevelFlags.Info,
                                    new DateTime(2015, 10, 7, 19, 51, 42, 483))
                    });
                }
            }
        }