I am writing a program in visual c# to filter error messages from a .log file and display them. There is a list named "contentList" and there's a list named "errorList"
void BtnCheckLeft_Click(object sender, EventArgs e)
{
SearchForErrors(_ContentListLeft);
}
void BtnCheckRight_Click(object sender, EventArgs e)
{
SearchForErrors(_ContentListRight);
}
void SearchForErrors(List<string> contentList)
{
int searchIndex = 1;
List<string> errorList = new List<string>();
while(searchIndex != errorList.Count)
{
var bla = contentList.BinarySearch("Error");
searchIndex += 1;
}
MessageBox.Show("Following errors were spotted:\n\n" + errorList.ToString() + "\n \n \n", "placeholder", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
contentList contains every line of the chosen .log file, now I want to put all entries that contain the word error in the list "errorList" and display it. My problem is that the BinarySearch finds nothing, bla (my placeholder var) is constantly -1 and I don't know another way to manage this. Maybe you know why the BinarySearch finds nothing or you know another way to display the error lines.
If your log file is a text file then you can do something like this:
string result = string.Empty;
var lines = File.ReadAllLines("myLogFile.txt");
foreach (var line in lines)
{
if(line.Contains("Error"))
{
errorList.Add(line);
}
}