log4net 可以统计已记录了多少错误跟踪吗?
对于某些硬件的 C# 回归测试模拟,我们使用 log4net 来跟踪模拟的执行情况。 每次出现问题时都会记录错误,当然,错误应该为零。 我们使用错误计数来确定测试的通过/失败,目前我们在日志中搜索 ERROR 来确定这一点。
是否可以从 log4net 检索每次记录错误时都会增加的错误计数? 我发现可以将错误记录到单独的文件中,但这并不完全是我们想要的,当然,通过一些修改,我们可以间接从中提取信息。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将直接记录到数据库或创建一个例程将日志文件导入到数据库中。 一旦日志位于数据库表中,就可以使用 SQL 轻松查询它们。
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.
我想不出任何直接内置到 log4net 中的东西。
要么使用一些内置的附加程序,让您按照 Jaime 的建议计算错误发生次数,要么创建自己的附加程序来完全满足您的要求。
它并不太复杂,特别是因为您计划使用 log4net 来自动化整个测试过程。
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.
正如康拉德建议的那样,自己动手。 您应该对ForwardingAppender进行子类化,使其对通往“真实”附加程序的消息进行计数。 附加器可以将实际计数记录到单独的附加器。
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.