public void TestClear2()
        {
            const string fname = "TestClear2.log";

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

            using (var logFile = new TextLogFile(_scheduler, fname))
            {
                var listener = new Mock <ILogFileListener>();
                var sections = new List <LogFileSection>();
                listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>()))
                .Callback((ILogFile log, LogFileSection section) => sections.Add(section));
                logFile.AddListener(listener.Object, TimeSpan.Zero, 2);

                logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(1);

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

                    logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(0);
                    sections.Should().EndWith(LogFileSection.Reset);
                }
            }
        }
예제 #2
0
        public void TestFilter2()
        {
            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")))
                {
                    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.Property(x => x.Count).ShouldEventually().Be(5, TimeSpan.FromSeconds(5));

                    filtered.AddListener(listener.Object, TimeSpan.Zero, 1);

                    sections.Should().Equal(new object[]
                    {
                        LogFileSection.Reset,
                        new LogFileSection(0, 1),
                        new LogFileSection(1, 1),
                        new LogFileSection(2, 1),
                        new LogFileSection(3, 1),
                        new LogFileSection(4, 1)
                    });
                }
            }
        }
        public void TestDelete1()
        {
            const string fname = "TestDelete1.log";

            File.WriteAllText(fname, "Test");

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

                new Action(() =>
                {
                    for (int i = 0; i < 10; ++i)
                    {
                        try
                        {
                            File.Delete(fname);
                            return;
                        }
                        catch (IOException)
                        {
                        }
                    }

                    File.Delete(fname);
                }).Should().NotThrow();
            }
        }
예제 #4
0
        public void TestSearch1()
        {
            var settings = new DataSource(TextLogFileAcceptanceTest.File2Mb)
            {
                Id = DataSourceId.CreateNew()
            };

            using (var logFile = new TextLogFile(_taskScheduler, TextLogFileAcceptanceTest.File2Mb))
                using (var dataSource = new SingleDataSource(_taskScheduler, settings, logFile, TimeSpan.Zero))
                {
                    var model = new SingleDataSourceViewModel(dataSource, new Mock <IActionCenter>().Object);

                    logFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                    model.Property(x =>
                    {
                        x.Update();
                        return(x.TotalCount);
                    }).ShouldEventually().Be(16114);

                    //model.Update();
                    //model.TotalCount.Should().Be(16114);

                    model.SearchTerm = "RPC #12";
                    var search = dataSource.Search;
                    search.Property(x => x.Count).ShouldEventually().Be(334);

                    model.Update();
                    model.SearchResultCount.Should().Be(334);
                    model.CurrentSearchResultIndex.Should().Be(0);
                }
        }
예제 #5
0
        public void Test2SmallSources()
        {
            using (var source0 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Entries))
                using (var source1 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Lines))
                    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))
                            {
                                source0.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();
                                source1.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                                multi0.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();
                                multi1.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                                merged.Property(x => x.Count).ShouldEventually().Be(8, TimeSpan.FromSeconds(5),
                                                                                    "Because the merged file should've been finished");
                                merged.Property(x => x.GetValue(LogFileProperties.Size)).ShouldEventually().Be(source0.GetValue(LogFileProperties.Size) + source1.GetValue(LogFileProperties.Size));
                                merged.Property(x => x.GetValue(LogFileProperties.StartTimestamp)).ShouldEventually().Be(source1.GetValue(LogFileProperties.StartTimestamp));

                                LogLine[] source0Lines = multi0.GetSection(new LogFileSection(0, source0.Count));
                                LogLine[] source1Lines = multi1.GetSection(new LogFileSection(0, source1.Count));
                                LogLine[] mergedLines  = merged.GetSection(new LogFileSection(0, merged.Count));

                                mergedLines[0].Should().Be(new LogLine(0, 0, new LogLineSourceId(1), source1Lines[0]));
                                mergedLines[1].Should().Be(new LogLine(1, 1, new LogLineSourceId(0), source0Lines[0]));
                                mergedLines[2].Should().Be(new LogLine(2, 1, new LogLineSourceId(0), source0Lines[1]));
                                mergedLines[3].Should().Be(new LogLine(3, 1, new LogLineSourceId(0), source0Lines[2]));
                                mergedLines[4].Should().Be(new LogLine(4, 2, new LogLineSourceId(1), source1Lines[1]));
                                mergedLines[5].Should().Be(new LogLine(5, 3, new LogLineSourceId(0), source0Lines[3]));
                                mergedLines[6].Should().Be(new LogLine(6, 3, new LogLineSourceId(0), source0Lines[4]));
                                mergedLines[7].Should().Be(new LogLine(7, 3, new LogLineSourceId(0), source0Lines[5]));
                            }
        }
        public void TestReadAll3()
        {
            using (var file = new TextLogFile(_scheduler, File20Mb))
            {
                file.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(20)).BeTrue();

                file.Count.Should().Be(165342);
                file.MaxCharactersPerLine.Should().Be(218);
            }
        }
 public void TestTimestampFormat5()
 {
     using (var file = new TextLogFile(_scheduler, @"TestData\Timestamps\yyyy MMM dd HH_mm_ss.fff.txt"))
     {
         file.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(5)).BeTrue();
         file.Count.Should().Be(2);
         var line = file.GetLine(1);
         line.Timestamp.Should().Be(new DateTime(2017, 5, 9, 6, 51, 57, 583, DateTimeKind.Unspecified));
     }
 }
 public void TestTimestampFormat4()
 {
     using (var file = new TextLogFile(_scheduler, @"TestData\Timestamps\ddd MMM dd HH_mm_ss.fff yyyy.txt"))
     {
         file.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5));
         file.Count.Should().Be(1);
         var line = file.GetLine(0);
         line.Timestamp.Should().Be(new DateTime(2017, 5, 5, 8, 46, 44, 257, DateTimeKind.Unspecified));
     }
 }
 public void TestTimestampFormat1()
 {
     using (var file = new TextLogFile(_scheduler, @"TestData\Timestamps\yyyy-MM-dd HH_mm_ss_fff.txt"))
     {
         file.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5));
         file.Count.Should().Be(1);
         var line = file.GetLine(0);
         line.Timestamp.Should().Be(new DateTime(2017, 5, 10, 20, 40, 3, 143, DateTimeKind.Unspecified));
     }
 }
예제 #10
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);
                }
            }
        }
예제 #11
0
        public void TestGetSection1()
        {
            using (var file = new TextLogFile(_scheduler, File20Mb))
            {
                file.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(5)).BeTrue("because we should be able to read the entire file in a few seconds");
                file.Count.Should().Be(165342);
                file.GetValue(LogFileProperties.StartTimestamp).Should().Be(new DateTime(2015, 10, 7, 19, 50, 58, 982));

                LogLine[] section = file.GetSection(new LogFileSection(0, 10));
                section.Should().Equal(new[]
                {
                    new LogLine(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)),
                    new LogLine(1,
                                "2015-10-07 19:50:58,998 [8092, 1] DEBUG SharpRemote.Hosting.OutOfProcessSiloServer (null) - Args.Length: 1",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 58, 998)),
                    new LogLine(2,
                                "2015-10-07 19:50:59,013 [8092, 1] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - Creating new servant (#18446744073709551613) 'SharpRemote.Heartbeat' implementing 'SharpRemote.IHeartbeat'",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 013)),
                    new LogLine(3,
                                "2015-10-07 19:50:59,062 [8092, 1] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - Creating new servant (#18446744073709551614) 'SharpRemote.Latency' implementing 'SharpRemote.ILatency'",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 062)),
                    new LogLine(4,
                                "2015-10-07 19:50:59,067 [8092, 1] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - Creating new servant (#18446744073709551615) 'SharpRemote.Hosting.SubjectHost' implementing 'SharpRemote.Hosting.ISubjectHost'",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 067)),
                    new LogLine(5,
                                "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(6,
                                "2015-10-07 19:50:59,141 [8092, 6] DEBUG SharpRemote.SocketRemotingEndPointServer (null) - Incoming connection from '127.0.0.1:10348', starting handshake...",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 141)),
                    new LogLine(7,
                                "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(8,
                                "2015-10-07 19:50:59,181 [8092, 10] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - 0.0.0.0:49152 to 127.0.0.1:10348: sending RPC #1 to 18446744073709551611.Beat",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 181)),
                    new LogLine(9,
                                "2015-10-07 19:50:59,182 [8092, 11] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - 0.0.0.0:49152 to 127.0.0.1:10348: sending RPC #2 to 18446744073709551612.Roundtrip",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 182))
                });
            }
        }
예제 #12
0
 public void TestTimestampFormat3()
 {
     using (var file = new TextLogFile(_scheduler, @"TestData\Timestamps\HH_mm_ss.txt"))
     {
         file.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(5)).BeTrue();
         file.Count.Should().Be(1);
         var line  = file.GetLine(0);
         var today = DateTime.Today;
         line.Timestamp.Should().Be(new DateTime(today.Year, today.Month, today.Day, 21, 04, 33, DateTimeKind.Unspecified));
     }
 }
예제 #13
0
        public void TestLive2()
        {
            const string fname = "TestLive2.log";

            if (File.Exists(fname))
            {
                File.Delete(fname);
            }

            using (var logger = new FileLogger(fname))
                using (var logFile = new TextLogFile(_scheduler, fname))
                {
                    logFile.Count.Should().Be(0);

                    Log.Info("Hello");
                    logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(1);

                    Log.Info("world!");
                    logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(2);
                }
        }
        public void TestTimestampFormat6()
        {
            using (var file = new TextLogFile(_scheduler, @"TestData\Timestamps\HH_mm_ss;s.txt"))
            {
                file.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5));
                file.Count.Should().Be(2);

                var today = DateTime.Today;
                var line  = file.GetLine(0);
                line.Timestamp.Should().Be(new DateTime(today.Year, today.Month, today.Day, 6, 51, 57, 135, DateTimeKind.Unspecified));
                line = file.GetLine(1);
                line.Timestamp.Should().Be(new DateTime(today.Year, today.Month, today.Day, 6, 53, 06, 341, DateTimeKind.Unspecified));
            }
        }
예제 #15
0
        public void TestClear1()
        {
            const string fname = "TestClear1.log";

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

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

                logFile.Count.Should().Be(1);

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

                        logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(0);
                        logFile.Count.Should().Be(0);

                        writer.WriteLine("Hello World!");
                        writer.Flush();

                        logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(1);
                        logFile.Entries.Should().Equal(new[]
                        {
                            new LogLine(0, "Hello World!", LevelFlags.Other)
                        });
                    }
            }
        }
        public void TestLive1()
        {
            const string fname = "TestLive1.log";

            if (File.Exists(fname))
            {
                File.Delete(fname);
            }

            using (var logger = new Logger(fname))
                using (var logFile = new TextLogFile(_scheduler, fname))
                {
                    logFile.Count.Should().Be(0);

                    Log.Info("Test");

                    logFile.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5));
                }
        }
예제 #17
0
        public void TestReadAll1()
        {
            using (var file = new TextLogFile(_scheduler, File20Mb))
            {
                file.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(20)).BeTrue();

                file.Dispose();

                file.GetValue(LogFileProperties.StartTimestamp).Should().Be(new DateTime(2015, 10, 7, 19, 50, 58, 982));

                List <LogLine> entries = file.Entries.ToList();
                entries.Count.Should().Be(165342);
                entries[0].Should()
                .Be(new LogLine(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)));
                entries[entries.Count - 1].Should()
                .Be(new LogLine(165341,
                                "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)));
            }
        }
예제 #18
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))
                    });
                }
            }
        }
예제 #19
0
        public void Test20Mb()
        {
            using (var source = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File20Mb))
                using (var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source))
                {
                    source.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                    merged.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue();

                    merged.Count.Should().Be(source.Count);
                    merged.GetValue(LogFileProperties.Size).Should().Be(source.GetValue(LogFileProperties.Size));
                    merged.GetValue(LogFileProperties.StartTimestamp).Should().Be(source.GetValue(LogFileProperties.StartTimestamp));

                    LogLine[] sourceLines = source.GetSection(new LogFileSection(0, source.Count));
                    LogLine[] mergedLines = merged.GetSection(new LogFileSection(0, merged.Count));
                    for (int i = 0; i < source.Count; ++i)
                    {
                        LogLine mergedLine = mergedLines[i];
                        LogLine sourceLine = sourceLines[i];
                        mergedLine.Should().Be(sourceLine);
                    }
                }
        }
예제 #20
0
        public void TestReadAll2()
        {
            using (var file = new TextLogFile(_scheduler, File20Mb))
            {
                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));

                file.AddListener(listener.Object, TimeSpan.Zero, 1);

                file.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(20)).BeTrue();
                file.Count.Should().Be(165342);

                sections[0].Should().Equal(LogFileSection.Reset);
                for (int i = 1; i < sections.Count; ++i)
                {
                    LogFileSection change = sections[i];
                    change.Index.Should().Be((LogLineIndex)(i - 1));
                    change.Count.Should().Be(1);
                }
            }
        }