Hi all I have a log file in the format below as you can see each log start with a time and ends with pipe delimeter.
Put each Log starting with a dateTime and ending with a pipe delimeter in a List
How can I parse this text file and put the logs in the collections? I seem to have a problem in determine how can I find the start and end of a log and read it each log
Below is a quick example to give an idea of what I am trying to do. Any pointers help etc... really appreciated
Log example
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|
File 2 Scenario My Order
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
============================================
Program:
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
}