Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
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]));
                            }
        }
Ejemplo n.º 3
0
        public void TestOpenBeforeCreate()
        {
            TextLogFile logFile = null;

            try
            {
                string fileName = Path.GetTempFileName();
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                new Action(() => logFile = new TextLogFile(_scheduler, fileName)).Should().NotThrow();

                logFile.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(5)).BeTrue();
                logFile.Property(x => x.GetValue(LogFileProperties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(ErrorFlags.SourceDoesNotExist,
                                                                                                                         "Because the specified file doesn't exist");

                File.WriteAllText(fileName, "Hello World!");

                logFile.Property(x => x.GetValue(LogFileProperties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(ErrorFlags.None,
                                                                                                                         "Because the file has been created now");
                logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(1, "Because one line was written to the file");

                logFile.GetLine(0).Should().Be(new LogLine(0, 0, "Hello World!", LevelFlags.Other));
            }
            finally
            {
                if (logFile != null)
                {
                    logFile.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        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);
                }
            }
        }
Ejemplo n.º 5
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)
                    });
                }
            }
        }
Ejemplo n.º 6
0
        protected override ILogFile CreateEmpty()
        {
            var logFile = new TextLogFile(_scheduler, "fawwaaw");

            _scheduler.RunOnce();
            return(logFile);
        }
Ejemplo n.º 7
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);
                }
        }
Ejemplo n.º 8
0
        public void TestMultilineNoLevel2()
        {
            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 entries = multi.GetEntries(new List <LogLineIndex>
                    {
                        new LogLineIndex(0),
                        new LogLineIndex(1),
                        new LogLineIndex(2),
                        new LogLineIndex(3),
                        new LogLineIndex(4),
                        new LogLineIndex(5)
                    },
                                                   LogFileColumns.Timestamp,
                                                   LogFileColumns.LogEntryIndex,
                                                   LogFileColumns.LineNumber,
                                                   LogFileColumns.RawContent);

                    var line = entries[0];
                    line.GetValue(LogFileColumns.Timestamp).Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 177));
                    line.GetValue(LogFileColumns.LogEntryIndex).Should().Be(new LogEntryIndex(0));
                    line.GetValue(LogFileColumns.LineNumber).Should().Be(1);
                    line.GetValue(LogFileColumns.RawContent).Should().Be("2019-03-18 14:09:54:177 1 00:00:00:0000000 Information Initialize Globals");

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

                    line = entries[2];
                    line.GetValue(LogFileColumns.Timestamp).Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 313));
                    line.GetValue(LogFileColumns.LogEntryIndex).Should().Be(new LogEntryIndex(1));
                    line.GetValue(LogFileColumns.LineNumber).Should().Be(3);
                    line.GetValue(LogFileColumns.RawContent).Should().Be("2019-03-18 14:09:54:313 1 00:00:00:0000000 Information   Loading");

                    line = entries[3];
                    line.GetValue(LogFileColumns.Timestamp).Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 313));
                    line.GetValue(LogFileColumns.LogEntryIndex).Should().Be(new LogEntryIndex(1));
                    line.GetValue(LogFileColumns.LineNumber).Should().Be(4);
                    line.GetValue(LogFileColumns.RawContent).Should().Be("preferences Started BTPVM3372 05:30:00 6060");

                    line = entries[4];
                    line.GetValue(LogFileColumns.Timestamp).Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 551));
                    line.GetValue(LogFileColumns.LogEntryIndex).Should().Be(new LogEntryIndex(2));
                    line.GetValue(LogFileColumns.LineNumber).Should().Be(5);
                    line.GetValue(LogFileColumns.RawContent).Should().Be("2019-03-18 14:09:54:551 1 00:00:00:0000000 Information    RMClientURL:");

                    line = entries[5];
                    line.GetValue(LogFileColumns.Timestamp).Should().Be(new DateTime(2019, 3, 18, 14, 9, 54, 551));
                    line.GetValue(LogFileColumns.LogEntryIndex).Should().Be(new LogEntryIndex(2));
                    line.GetValue(LogFileColumns.LineNumber).Should().Be(6);
                    line.GetValue(LogFileColumns.RawContent).Should().Be("BTPVM3372 05:30:00 6060");
                }
        }
 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));
     }
 }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
 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));
     }
 }
Ejemplo n.º 13
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));
     }
 }
Ejemplo n.º 14
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))
                });
            }
        }
        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));
            }
        }
Ejemplo n.º 16
0
        public void TestTranslator1()
        {
            var translator = new Mock <ILogLineTranslator>();

            _file = new TextLogFile(_scheduler, _fname, translator: translator.Object);
            _file.AddListener(_listener.Object, TimeSpan.Zero, 10);

            _streamWriter.Write("Foo");
            _streamWriter.Flush();
            _scheduler.RunOnce();

            translator.Verify(x => x.Translate(It.Is <ILogFile>(y => y == _file), It.IsAny <LogLine>()),
                              Times.Once);
        }
Ejemplo n.º 17
0
        public void TestExclusiveAccess()
        {
            _streamWriter?.Dispose();
            _stream?.Dispose();

            using (var stream = new FileStream(_fname, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                _file = new TextLogFile(_scheduler, _fname);
                _scheduler.RunOnce();

                _file.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceCannotBeAccessed);
                _file.GetValue(LogFileProperties.Created).Should().NotBe(DateTime.MinValue);
                _file.GetValue(LogFileProperties.Created).Should().Be(new FileInfo(_fname).CreationTime);
            }
        }
Ejemplo n.º 18
0
        public void TestDoesNotExist()
        {
            _file = new TextLogFile(_scheduler, _fname);
            _scheduler.RunOnce();
            _file.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.None);
            _file.GetValue(LogFileProperties.Created).Should().NotBe(DateTime.MinValue);

            _streamWriter?.Dispose();
            _stream?.Dispose();
            File.Delete(_fname);
            _scheduler.RunOnce();

            _file.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist);
            _file.GetValue(LogFileProperties.Created).Should().BeNull();
        }
Ejemplo n.º 19
0
        public void TestEncodingLatin1()
        {
            _binaryWriter.Write((byte)0x36);
            _binaryWriter.Write((byte)0x35);
            _binaryWriter.Write((byte)0xB0);
            _binaryWriter.Write((byte)'\r');
            _binaryWriter.Write((byte)'\n');
            _binaryWriter.Flush();

            _file = new TextLogFile(_scheduler, _fname, encoding: Encoding.GetEncoding(1252));
            _scheduler.RunOnce();

            _file.Count.Should().Be(1);
            var line = _file.GetLine(0);

            line.Message.Should().Be("65°");
        }
Ejemplo n.º 20
0
        public void SetUp()
        {
            _fname = Path.GetTempFileName();
            if (File.Exists(_fname))
            {
                File.Delete(_fname);
            }
            _scheduler = new ManualTaskScheduler();

            _stream  = File.Open(_fname, FileMode.Create, FileAccess.Write, FileShare.Read);
            _writer  = new StreamWriter(_stream);
            _logFile = new TextLogFile(_scheduler, _fname);

            _settings = new DataSource(_fname)
            {
                Id = DataSourceId.CreateNew()
            };
        }
 public void Test()
 {
     using (var source1 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Entries))
         using (var source2 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Lines))
         {
             var sources = new List <ILogFile> {
                 source1, source2
             };
             using (var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(10), sources))
             {
                 var filter = new SubstringFilter("foo", true);
                 using (var filtered = new FilteredLogFile(_scheduler, TimeSpan.FromMilliseconds(10), merged, null, filter))
                 {
                     filtered.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5));
                 }
             }
         }
 }
Ejemplo n.º 22
0
        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");
                }
        }
Ejemplo n.º 23
0
        public void TestLive1()
        {
            const string fname = "TestLive1.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("Test");

                    logFile.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(1);
                }
        }
Ejemplo n.º 24
0
        protected override ILogFile CreateFromContent(IReadOnlyLogEntries content)
        {
            var fname = Path.GetTempFileName();

            using (var stream = File.OpenWrite(fname))
                using (var writer = new StreamWriter(stream))
                {
                    foreach (var logEntry in content)
                    {
                        writer.Write(logEntry.ToString());
                        writer.WriteLine();
                    }
                }

            var logFile = new TextLogFile(_scheduler, fname);

            _scheduler.RunOnce();
            return(logFile);
        }
Ejemplo n.º 25
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);
                }
            }
        }
Ejemplo n.º 26
0
        public void TestRead2LogEntries()
        {
            using (var file = new TextLogFile(_scheduler, File2Entries))
            {
                var listener = new Mock <ILogFileListener>();
                var changes  = new List <LogFileSection>();
                listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>()))
                .Callback((ILogFile logFile, LogFileSection section) => changes.Add(section));

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

                changes.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(7);

                changes.Should().Equal(new[]
                {
                    LogFileSection.Reset,
                    new LogFileSection(0, 1),
                    new LogFileSection(1, 1),
                    new LogFileSection(2, 1),
                    new LogFileSection(3, 1),
                    new LogFileSection(4, 1),
                    new LogFileSection(5, 1)
                });

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

                LogLine[] lines = file.GetSection(new LogFileSection(0, 6));
                lines.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)),
                    new LogLine(1, 1, "Foobar", LevelFlags.Other, null),
                    new LogLine(2, 2, "Some more info", LevelFlags.Other, null),
                    new LogLine(3, 3,
                                "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(4, 4, "Hey look at me", LevelFlags.Other, null),
                    new LogLine(5, 5, "dwadawdadw", LevelFlags.Other, null)
                });
            }
        }
Ejemplo n.º 27
0
        public void TestRead2Lines()
        {
            using (var file = new TextLogFile(_scheduler, File2Lines))
            {
                var listener = new Mock <ILogFileListener>();
                var changes  = new List <LogFileSection>();
                listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>()))
                .Callback((ILogFile logFile, LogFileSection section) => changes.Add(section));

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

                changes.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(3);
                changes.Should().Equal(new[]
                {
                    LogFileSection.Reset,
                    new LogFileSection(0, 1),
                    new LogFileSection(1, 1)
                });
            }
        }
        public void TestDoesNotExist()
        {
            TextLogFile logFile = null;

            try
            {
                new Action(() => logFile = new TextLogFile(_scheduler, "dadwdawdw")).ShouldNotThrow();

                logFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5));
                logFile.Property(x => x.GetValue(LogFileProperties.EmptyReason)).ShouldEventually().Be(ErrorFlags.SourceDoesNotExist, TimeSpan.FromSeconds(5));

                logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist, "Because the specified file doesn't exist");
            }
            finally
            {
                if (logFile != null)
                {
                    logFile.Dispose();
                }
            }
        }
Ejemplo n.º 29
0
        public void TestExists()
        {
            TextLogFile logFile = null;

            try
            {
                new Action(() => logFile = new TextLogFile(_scheduler, File2Lines)).Should().NotThrow();

                logFile.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(5)).BeTrue();
                logFile.Property(x => x.GetValue(LogFileProperties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(ErrorFlags.None);

                logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.None, "Because the specified file does exist");
            }
            finally
            {
                if (logFile != null)
                {
                    logFile.Dispose();
                }
            }
        }
        public void TestLive2()
        {
            const string fname = "TestLive2.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("Hello");
                    logFile.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5));

                    Log.Info("world!");
                    logFile.Property(x => x.Count).ShouldEventually().Be(2, TimeSpan.FromSeconds(5));
                }
        }