views:

130

answers:

3

Hi all,

For a C# regression test simulation of some hardware we're using log4net to trace the execution of the simulation. Errors are logged every time something goes wrong, and there should be zero errors, of course. We use the error count to determine pass/fail of the test, currently we search the log for ERROR to determine this.

Is it possible to retrieve an error count from log4net that increments every time an error is logged? I see that it is possible to log errors to a separate file but this is not exactly what we want, although with some fiddling we could extract the information indirectly from it, of course.

Thanks in advance.

+1  A: 

I would log directly to a database or create a routine to import the log files into a database. Once the logs are in a database table they can be easily queried with SQL.

Jamie Ide
Thanks for your quick response - I was hoping for a more direct possibility to query log4net's internals retrieve a count from there.There are several possible indirect workarounds - a .NET file watcher on the error file looking for changes would also allow an error count to be created.
A: 

I can not think of anything directly built into log4net.

Either use some built-in appender that will let you count error occurences as Jaime suggested or alternatively create your own appender that will do exactly you want. It is not too complicated especially since you plan using log4net to automate your whole testing process.

Konrad
Many thanks, that saves me looking further for something that probably doesn't exist. Do you have a favourite guide for writing appenders? The documentation seems to be, shall we say, fragmented...
A: 

As Konrad suggests, roll your own. You should subclassForwardingAppender, making it count messages on their way to the "real" appenders. The appender could log the actual counts to a separate appender.

Peter Lillevold