public async Task ParseSharepointLogs(string fileName, int recordCount) { var parser = new AsyncULSLogParser(NullLogger.Instance, null, 1024); var records = new List <IEnvelope <KeyValueLogRecord> >(); await parser.ParseRecordsAsync(new DelimitedTextLogContext { FilePath = Path.Combine(AppContext.BaseDirectory, fileName) }, records, int.MaxValue); Assert.Equal(recordCount, records.Count); }
public async Task RemoveStartFromTimestamp(string timestampField) { var logs = new string[] { $"{timestampField}\t field1\tfield2 \t field3 ", $"{DateTime.Now}* \t value1\t value2 \t value3 " }; await File.WriteAllLinesAsync(_testFile, logs); var parser = new AsyncULSLogParser(NullLogger.Instance, null, 1024); var records = new List <IEnvelope <KeyValueLogRecord> >(); await parser.ParseRecordsAsync(new DelimitedTextLogContext { FilePath = _testFile }, records, int.MaxValue); Assert.Single(records); var record = records[0]; Assert.DoesNotContain("*", record.Data[timestampField]); }
private static async Task TestWssLogsWithContext(DelimitedTextLogContext context) { var parser = new AsyncULSLogParser(NullLogger.Instance, null, 1024); var output = new List <IEnvelope <KeyValueLogRecord> >(); await parser.ParseRecordsAsync(context, output, 10); Assert.Equal(2, output.Count); var record = output[0].Data; _ = output[0].GetMessage("json"); Assert.Equal("03/07/2018 22:54:54.97", record["Timestamp"]); Assert.Equal(new DateTime(2018, 3, 7, 22, 54, 54, 970), record.Timestamp); Assert.Equal("SharePoint Foundation", record["Area"]); Assert.Equal("Warning", record["Level"]); var envelope = (ILogEnvelope)output[0]; Assert.Equal(2, envelope.LineNumber); Assert.Equal("03/07/2018 22:54:54.97", output[1].Data["Timestamp"]); }
public async Task KeysAndValuesAreTrimmed() { var logs = new string[] { "Timestamp\t field1\tfield2 \t field3 ", $"{DateTime.Now} \t value1\t value2 \t value3 " }; await File.WriteAllLinesAsync(_testFile, logs); var parser = new AsyncULSLogParser(NullLogger.Instance, null, 1024); var records = new List <IEnvelope <KeyValueLogRecord> >(); await parser.ParseRecordsAsync(new DelimitedTextLogContext { FilePath = _testFile }, records, int.MaxValue); Assert.Single(records); var record = records[0]; Assert.True(record.Data.Keys.All(k => !k.StartsWith(" ") && !k.EndsWith(" "))); Assert.True(record.Data.Values.All(v => !v.StartsWith(" ") && !v.EndsWith(" "))); }