У меня есть файл журнала в следующем формате, так как вы можете увидеть каждый запуск журнала с течением времени и заканчиваться трубным делителем.Разбор текстового файла с использованием Linq
Разложите журнала, начиная с DATETIME и заканчивая вертикальной чертой в списке
Как я могу разобрать этот текстовый файл и поместить журналы в коллекции? У меня, кажется, есть проблема в определении того, как я могу найти начало и конец журнала и прочитать его каждый журнал.
Ниже приведен краткий пример, чтобы дать представление о том, что я пытаюсь сделать. Любые указатели помогают и т.д ... действительно оценил
пример журнала
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