public async Task TestSampleSyslogFile() { var filePath = Path.Combine(AppContext.BaseDirectory, "Samples/syslogsample.log"); var lines = await File.ReadAllLinesAsync(filePath); var parser = new SyslogLogParser(NullLogger.Instance, false, null, 1024); var records = new List <IEnvelope <SyslogData> >(); await parser.ParseRecordsAsync(new LogContext { FilePath = filePath }, records, 1000, default); Assert.Equal(lines.Length, records.Count); for (var i = 0; i < lines.Length; i++) { var record = records[i] as LogEnvelope <SyslogData>; Assert.Equal(lines[i], record.ToString()); Assert.Equal(i + 1, record.LineNumber); } }
public async Task TestSyslogParser(string logLine, DateTime expectedDateTime, string hostname, string program, string message, string syslogTimestamp) { await File.WriteAllLinesAsync(_testFile, new string[] { logLine }); var parser = new SyslogLogParser(NullLogger.Instance, false, null, 1024); var records = new List <IEnvelope <SyslogData> >(); await parser.ParseRecordsAsync(new LogContext { FilePath = _testFile }, records, 10, default); Assert.Single(records); var record = records[0]; // make sure the Timestamp of the envelope is in universal time Assert.Equal(expectedDateTime.ToUniversalTime(), record.Timestamp); // assert extracted syslog data Assert.Equal(hostname, record.Data.Hostname); Assert.Equal(program, record.Data.Program); Assert.Equal(message, record.Data.Message); Assert.Equal(syslogTimestamp, record.Data.SyslogTimestamp); }