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.
对于某些硬件的C#回归测试模拟,我们使用log4net来跟踪模拟的执行。每次出错时都会记录错误,当然应该没有错误。我们使用错误计数来确定测试的通过/失败,目前我们在日志中搜索ERROR以确定这一点。
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.
是否可以从log4net中检索错误计数,每次记录错误时都会递增?我看到可以将错误记录到一个单独的文件中,但这并不是我们想要的,尽管有一些小问题,我们可以间接地从它中提取信息。
Thanks in advance.
提前致谢。
3 个解决方案
#1
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.
我会直接登录到数据库或创建例程将日志文件导入数据库。一旦日志在数据库表中,就可以使用SQL轻松查询它们。
#2
I can not think of anything directly built into log4net.
我想不出任何直接内置到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.
使用一些内置的appender,可以让你计算Jaime建议的错误发生,或者创建你自己的appender,它将完全你想要的。它并不太复杂,特别是因为您计划使用log4net来自动化整个测试过程。
#3
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.
正如康拉德建议的那样,滚动你自己。你应该sublassForwardingAppender,让它在去往“真正的”appender的路上计算消息。 appender可以将实际计数记录到单独的appender中。
#1
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.
我会直接登录到数据库或创建例程将日志文件导入数据库。一旦日志在数据库表中,就可以使用SQL轻松查询它们。
#2
I can not think of anything directly built into log4net.
我想不出任何直接内置到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.
使用一些内置的appender,可以让你计算Jaime建议的错误发生,或者创建你自己的appender,它将完全你想要的。它并不太复杂,特别是因为您计划使用log4net来自动化整个测试过程。
#3
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.
正如康拉德建议的那样,滚动你自己。你应该sublassForwardingAppender,让它在去往“真正的”appender的路上计算消息。 appender可以将实际计数记录到单独的appender中。