Beispiel #1
0
        public async Task TimeStampTimeZoneAdjustmentTest()
        {
            ClefParser pNormal = new ClefParser();

            ClefParser pAdjust = new ClefParser
            {
                TimeStampTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time")
            };

            CancellationTokenSource cts         = new CancellationTokenSource();
            string fileName                     = @"ClefExample1.clef";
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();

            var messages = (await pAdjust.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.IsTrue(messages.Count() == 4);
            var msgAdjust = messages.ElementAt(0);

            var messages2 = (await pNormal.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.IsTrue(messages2.Count() == 4);
            var msgOrig = messages2.ElementAt(0);

            var msgAdjustDate = msgAdjust.Date.ToUniversalTime();
            var expectedDate  = TimeZoneInfo
                                .ConvertTimeFromUtc(msgOrig.Date, pAdjust.TimeStampTimeZone)
                                .ToUniversalTime();

            Assert.IsTrue(msgAdjustDate == expectedDate);
        }
        public async Task SourceContextTest()
        {
            ClefParser p = new ClefParser();
            CancellationTokenSource cts         = new CancellationTokenSource();
            string fileName                     = @"SourceContextTest.clef";
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();

            var messages = (await p.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.AreEqual(2, messages.Count());

            // The first event doesn't have a source context
            var firstEvent = messages.ElementAt(0);

            Assert.AreEqual("Hello, Serilog!", firstEvent.Text);
            Assert.AreEqual(string.Empty, firstEvent.Source);
            Assert.AreEqual(1, firstEvent.ThreadId);
            Assert.IsNotNull(firstEvent.Module);
            Assert.IsNotNull(firstEvent.FileName);
            Assert.IsNotNull(firstEvent.Category);
            Assert.IsNotNull(firstEvent.User);
            Assert.IsNotNull(firstEvent.MethodName);
            // The second event should have a source context
            var secondEvent = messages.ElementAt(1);

            Assert.AreEqual("Contextual Log", secondEvent.Text);
            Assert.AreEqual("SerilogLogging.Program", secondEvent.Source);
            Assert.AreEqual(1, secondEvent.ThreadId);
            Assert.IsNotNull(secondEvent.Module);
            Assert.IsNotNull(secondEvent.FileName);
            Assert.IsNotNull(secondEvent.Category);
            Assert.IsNotNull(secondEvent.User);
            Assert.IsNotNull(secondEvent.MethodName);
        }
        public async Task ClefParserTest()
        {
            var p = new RegexOfflineDataProvider();

            p.SupportFormats = new List <string>()
            {
                "*.nlog"
            };
            CancellationTokenSource cts         = new CancellationTokenSource();
            string fileName                     = @"example.nlog";
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();

            var regexPattern = new RegexPattern(@"(?<Date>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}.\d{4})\|(?<Level>\w+)\|(?<Source>.+)\|(?<Text>.*)\|(?<ProcessName>.*)\|(?<ProcessId>.*)",
                                                "yyyy-MM-dd HH:mm:ss.ffff", "", new List <string> {
                "*.nlog"
            });

            if (!RegexParser.Managers.UserSettingsManager.UserSettings.Settings.RegexPatterns.Contains(regexPattern))
            {
                RegexParser.Managers.UserSettingsManager.UserSettings.Settings.RegexPatterns.Insert(0, regexPattern);
            }

            var messages = await p.Process(fileName, cts.Token, forTesting);

            Assert.IsTrue(messages.Count() == 4);
        }
        public async Task ClefParserTest()
        {
            ClefParser p = new ClefParser();
            CancellationTokenSource cts         = new CancellationTokenSource();
            string fileName                     = @"ClefExample1.clef";
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var messages = await p.Process(fileName, cts.Token, forTesting);

            Assert.IsTrue(messages.Count() == 4);
        }
        public async Task CompactJsonFormatParserTest()
        {
            CompactJsonFormatParser parser = new CompactJsonFormatParser();
            CancellationTokenSource cts    = new CancellationTokenSource();
            string fileName = Path.Combine(Folder, "log files", "CompactJsonFormat.clef");
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.IsTrue(messages.Count == 4);
            Assert.IsTrue(messages[0].Text == "Hello, { Name: \"nblumhardt\", Id: 101 }");
        }
Beispiel #6
0
        public async Task JsonFilePerFileTest()
        {
            JsonFileParser          parser = new JsonFileParser(new JsonFormatMessageFields());
            CancellationTokenSource cts    = new CancellationTokenSource();
            string fileName = Path.Combine(Folder, "log files", "JsonFormatPerFile.clef");
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.IsTrue(messages.Count == 2);
            //Assert.IsTrue(messages[0].Text == "Hello, { Name: \"nblumhardt\", Tags: [1, 2, 3] }, 0000007b at 06/07/2016 06:44:57","got"+ messages[0].Text);
            Assert.IsTrue(messages[0].User == "{ Name: \"nblumhardt\", Tags: [1, 2, 3] }");
        }
        public async Task OfflineProviderParserTimestampTest(string fileName, int numberOfMessages, string datetimeToParse)
        {
            OfflineDataProvider     parser = new OfflineDataProvider();
            CancellationTokenSource cts    = new CancellationTokenSource();
            string file = Path.Combine(Folder, "log files", fileName);
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var            messages             = (await parser.Process(file, cts.Token, forTesting)).ToList();
            DateTimeOffset dto = DateTimeOffset.Parse(datetimeToParse);

            Assert.IsTrue(messages.Count == numberOfMessages);
            Assert.IsTrue(messages[0].Date == dto.DateTime);
        }
        public async Task CompactJsonFormatTestGZFile()
        {
            CompactJsonFormatParser parser = new CompactJsonFormatParser();
            CancellationTokenSource cts    = new CancellationTokenSource();
            string fileName = Path.Combine(Folder, "log files", "CompactJsonFormat.gz");
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.AreEqual(4, messages.Count());
            // The first event doesn't have a source context
            Assert.IsTrue(messages[2].AdditionalInformation["Tags"] == "[\"test\", \"orange\"]");
        }
Beispiel #9
0
        public async Task CompactJsonFormatFullFileTest()
        {
            JsonFileParser          parser = new JsonFileParser(new CompactJsonFormatMessageFields());
            CancellationTokenSource cts    = new CancellationTokenSource();
            string fileName = Path.Combine(Folder, "log files", "JsonFileCompactFormat.clef");
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.IsTrue(messages.Count == 2);
            Assert.IsTrue(messages[0].MachineName == "MY-MACHINE");
            Assert.IsTrue(messages[1].Text.StartsWith("An unknown error occurred"));
            Assert.IsTrue((messages[1].Module == "My process"));
        }
        public async Task CompactJsonFormatTestColumns()
        {
            CompactJsonFormatParser parser = new CompactJsonFormatParser();
            CancellationTokenSource cts    = new CancellationTokenSource();
            string fileName = Path.Combine(Folder, "log files", "CompactJsonFormatTestColumns.clef");
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var messages = (await parser.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.AreEqual(4, messages.Count());
            // The first event doesn't have a source context
            Assert.IsTrue(messages[0].MachineName == "Test");
            Assert.IsTrue(messages[1].AdditionalInformation["CustomProperty"] == "\"Custom Value\"");
        }
Beispiel #11
0
        public async Task JsonFilePerLineDateTimeWithOffsetTest()
        {
            var p = new JsonFormatterParser(new JsonFormatMessageFields());
            CancellationTokenSource cts         = new CancellationTokenSource();
            string fileName                     = Path.Combine(Folder, "log files", "JsonFormatPerLine.clef");
            MessageHandlerForTesting forTesting = new MessageHandlerForTesting();
            var messages = (await p.Process(fileName, cts.Token, forTesting)).ToList();

            Assert.IsTrue(messages.Count == 2);

            Assert.IsTrue(messages[0].User == "{ Name: \"nblumhardt\", Tags: [1, 2, 3] }");

            DateTimeOffset dto = DateTimeOffset.Parse("2020-06-07T13:44:57.8532799+10:00");
            //Assert.IsTrue(messages[0].Date == dto.DateTime);
            //Assert.IsTrue(messages[0].Text == "Hello, { Name: \"nblumhardt\", Tags: [1, 2, 3] }, 0000007b at 06/07/2016 06:44:57", "got" + messages[0].Text);
        }