我有以下格式的日誌文件,您可以看到每個日誌以時間開始並以管道分隔符結束。使用Linq解析文本文件使用Linq解析文本文件
把每個日誌開始日期時間,並在列表與豎線分隔結束
我如何解析這個文本文件,並把日誌的藏品? 我在確定如何找到一個日誌的開始和結束並讀取它的每個日誌似乎有問題
下面是一個快速示例,讓我知道我正在嘗試做什麼。 任何指針幫助等..真的很感激
日誌例如
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|
文件2方案 我的訂單
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
}
與標準的處理方式相比,Linq的性能非常差。所以要小心解析,通常非常依賴於表演。 – 2010-09-18 16:41:40