public void TryParseTest_LineIsValid_ReturnTrue() { const string line = "2019-08-17 15:56:00,282 INFO - admin's role: Administrator"; bool result = LogModelParser.TryParse(line, out var logModel); Assert.True(result); }
public void TryParseTest_LineIsInvalid_ReturnFalse() { const string line = " admin's role: Administrator - INFO -"; bool result = LogModelParser.TryParse(line, out var logModel); Assert.False(result); }
public void ParseTest() { string line = "2019-08-17 15:56:00,282 INFO - admin's role: Administrator" + Environment.NewLine; var result = LogModelParser.Parse(line); Assert.Equal("2019-08-17 15:56:00,282", result.Date.Trim()); Assert.Equal("INFO", result.Level.Trim()); Assert.Equal("admin's role: Administrator", result.Message.Trim()); }
public override async Task OnLoadedAsync() { string logText = await SafelyReadTextFromLogAsync(); if (string.IsNullOrWhiteSpace(logText)) { return; } LogModels.Clear(); foreach (string line in SplitByNewline(logText)) { if (LogModelParser.TryParse(line, out var logModel)) { LogModels.Add(logModel); } } }