2

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Mister
  • 25
  • 6

2 Answers2

1

Using Regex:

Regex.Matches(fails, line).Count
Andrea
  • 6,032
  • 2
  • 28
  • 55
0

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));
rory.ap
  • 34,009
  • 10
  • 83
  • 174