private bool ValidateRegex(string directory, string logName, IConfigurationRoot config, IConfigurationSection sourceSection, string curId, IList <String> messages)
        {
            string log = GetLog(directory, logName).ToString();

            using (Stream stream = Utility.StringToStream(log))
                using (StreamReader sr = new StreamReader(stream))
                {
                    string pattern           = config[$"{sourceSection.Path}:{"Pattern"}"];
                    string timestampFormat   = config[$"{sourceSection.Path}:{"TimestampFormat"}"];
                    string extractionPattern = config[$"{sourceSection.Path}:{"ExtrationPattern"}"];

                    RegexRecordParser parser = new RegexRecordParser(pattern, timestampFormat, null, extractionPattern, DateTimeKind.Utc);
                    var records = parser.ParseRecords(sr, new LogContext()).ToList();
                    if (records.Count == 1)
                    {
                        messages.Add("Invalid Regex at source ID: " + curId);
                        return(false);
                    }
                    else
                    {
                        messages.Add("Valid Regex at source ID: " + curId);
                        return(true);
                    }
                }
        }
Esempio n. 2
0
        public void TestRegExtractor()
        {
            string log = @"[FATAL][2017/05/03 21:31:00.534][0x00003ca8][0000059c][][EQCASLicensingSubSystem][eqGetLicenseForSystemID][0] 'EQException.File: EQCASLicensingSubSystem.cpp'
[FATAL][2017/05/03 21:31:00.535][0x00003ca8][0000059c][][EQCASLicensingSubSystem][eqGetLicenseForSystemID][0] 'EQException.Line: 3999'";

            using (Stream stream = Utility.StringToStream(log))
                using (StreamReader sr = new StreamReader(stream))
                {
                    string extractionPatterm = @"^\[(?<Severity>\w+)\]" +
                                               @"\[(?<TimeStamp>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\]" +
                                               @"\[[^]]*\]" +
                                               @"\[[^]]*\]" +
                                               @"\[[^]]*\]" +
                                               @"\[(?<SubSystem>\w+)\]" +
                                               @"\[(?<Module>\w+)\]" +
                                               @"\[[^]]*\]" +
                                               @" '(?<Message>.*)'$";
                    RegexRecordParser parser = new RegexRecordParser(@"^\[\w+\]\[(?<TimeStamp>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\]",
                                                                     "yyyy/MM/dd HH:mm:ss.fff",
                                                                     null,
                                                                     extractionPatterm,
                                                                     null,
                                                                     DateTimeKind.Utc,
                                                                     new RegexRecordParserOptions()
                                                                     );
                    var records = parser.ParseRecords(sr, new LogContext()).ToList();

                    Assert.Equal("FATAL", records[0].Data["Severity"]);
                    Assert.Equal("2017/05/03 21:31:00.534", records[0].Data["TimeStamp"]);
                    Assert.Equal("EQCASLicensingSubSystem", records[0].Data["SubSystem"]);
                    Assert.Equal("eqGetLicenseForSystemID", records[0].Data["Module"]);
                    Assert.Equal("EQException.File: EQCASLicensingSubSystem.cpp", records[0].Data["Message"]);

                    Assert.Equal("2017/05/03 21:31:00.535", records[1].Data["TimeStamp"]);
                    Assert.Equal("EQException.Line: 3999", records[1].Data["Message"]);

                    var envelope = (ILogEnvelope)records[1];
                    Assert.Equal(2, envelope.LineNumber);
                }
        }
        public void TestPrintLog()
        {
            string log = @"[FATAL][2017/05/03 21:31:00.534][0x00003ca8][0000059c][][EQCASLicensingSubSystem][eqGetLicenseForSystemID][0] 'EQException.File: EQCASLicensingSubSystem.cpp'
[FATAL][2017/05/03 21:31:00.535][0x00003ca8][0000059c][][EQCASLicensingSubSystem][eqGetLicenseForSystemID][0] 'EQException.Line: 3999'";

            using (Stream stream = Utility.StringToStream(log))
                using (StreamReader sr = new StreamReader(stream))
                {
                    RegexRecordParser parser = new RegexRecordParser(@"^\[\w+\]\[(?<TimeStamp>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\]",
                                                                     "yyyy/MM/dd HH:mm:ss.fff", null, null, DateTimeKind.Utc, new RegexRecordParserOptions());
                    var records = parser.ParseRecords(sr, new LogContext()).ToList();

                    Assert.Equal("[FATAL][2017/05/03 21:31:00.534][0x00003ca8][0000059c][][EQCASLicensingSubSystem][eqGetLicenseForSystemID][0] 'EQException.File: EQCASLicensingSubSystem.cpp'", records[0].GetMessage(null));
                    Assert.Equal(new DateTime(2017, 5, 3, 21, 31, 0, 534), records[0].Timestamp);

                    Assert.Equal("[FATAL][2017/05/03 21:31:00.535][0x00003ca8][0000059c][][EQCASLicensingSubSystem][eqGetLicenseForSystemID][0] 'EQException.Line: 3999'", records[1].GetMessage(null));
                    Assert.Equal(new DateTime(2017, 5, 3, 21, 31, 0, 535), records[1].Timestamp);

                    var envelope = (ILogEnvelope)records[1];
                    Assert.Equal(2, envelope.LineNumber);
                }
        }