Error log with a counter

209 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 answers

0
Andrea On BEST ANSWER

Using Regex:

Regex.Matches(fails, line).Count
0
rory.ap 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));