Error log with a counter

225 Views Asked by At

I have a c# project and a log file with errors. I want to give all errors on a new log file out with a counter if there are some errors twice or more. I used the command:

bool alreadyExist = fails.Contains(line);

This works really good, but I want also a counter, to show how many times I have the same line in a log file.

2

There are 2 best solutions below

0
On BEST ANSWER

Using Regex:

Regex.Matches(fails, line).Count
0
On

Assuming fails is an IEnumerable<string> where each element is a log file line, this should work:

int count = fails.Count((x) => x.Equals(line));