我有一个日志文件,格式如下所示,可以看到每个日志都以时间开始,并以管道分隔符结束。
将每个以日期时间开头并以管道分隔符结尾的日志放入列表中
我该如何解析这个文本文件并将日志放入集合中? 我似乎有一个问题,无法确定如何找到日志的开始和结束,并读取每个日志。
以下是一个快速示例,以给出我正在尝试做什么的想法。 任何指针帮助等...真的很感激
日志示例
08:52:03.260|Error| Stack Trace and other info removed here|
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace|
09:52:03.260|Error| Stack Trace and other info removed here|
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace|
09:52:03.260|Error|Stack Trace and other info removed here|
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace
lots of info about the stack trace|
文件转场景 我的订单
Quantity Description Price
1 shoes £1.00
Total £1.00
No: 34343345
=============================================
My Order
Quantity Description Price
1 TShirt £1.00
Total £1.00
No: 32234234
============================================
程序:
class Program
{
static void Main(string[] args)
{
string path = @"MyTestLog.log";
string aa = string.Empty;
List<LogMessage>logMessages=new List<LogMessage>();
using (StreamReader reader = new StreamReader(path))
{
//????
logMessages.Add(new LogMessage
{
Time = ??,
ErrorLevel = ,
Details = ??
});
}
}
}
public class LogMessage
{
public DateTime Time { get; set; }
public string ErrorLevel { get; set; }
public string Details { get; set; }
//other stuff here
}