NUnit 和 Log4Net 集成:基于日志断言
这是我关于堆栈溢出的第一个问题。我没有太多运气通过谷歌或 stackoverflow 找到答案。
我感兴趣的是让 nunit 测试检查 log4net 中日志中的特定条目,并根据搜索结果进行断言。
根据我阅读的一篇不相关的文章:log4net,我想我可以使用 MemoryAppender 通过 GetEvents 方法并仔细阅读返回的事件数组来完成此操作。
但我想知道: 1.有人做过吗?有什么陷阱或建议吗?还有其他方法吗? 2. 有谁可以提供食谱吗?
谢谢。
This is my first question on stack overflow. I haven't had much luck finding an answer via google or stackoverflow.
I'm interested in having an nunit test examine the log4net for a specific entry in the log and assert based on the results of that search.
Based on an unrelated post I read re: log4net, I think I can probably use MemoryAppender to do this via the GetEvents method and perusing the array of events returned.
But I'm wondering:
1. Has anyone done this? Any pitfalls or suggestions? Any alternate approaches?
2. Does any have a recipe they could present?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,回答我自己的问题(或者更确切地说,我的同事是,谢谢贝丝)。
在 log4net 的配置中:
配置:
在您的 .net 代码中:
一旦获得消息数组,就可以执行您想要的操作。
如果您有现有日志文件并想要搜索它,则这无法解决。
Ok, answering my own question (or rather, my co-worker is, thanks Beth).
In your configuration for log4net:
config:
In your .net code:
Once you have the messages array, do what you want to.
This doesn't address if you have an existing log file and want to search it.