有人可以帮我使用 Log4net 设置 Ninject 2 吗?
我已经(愉快地)使用 Ninject 有一段时间了,现在有一些基本场景,并且想让它控制我的日志记录。我注意到 Ninject.Extensions.Logging 命名空间的存在,并想使用它,但我遇到了两个问题:
- 我希望使用运行它的类的类型来初始化记录器> (就像我使用 GetCurrentMethod().DeclaringType 运行 LogManager.GetLogger 一样)。
- 我希望能够轻松模拟或“无效”记录器以进行单元测试(即我不想让记录器工作),而不会因未初始化记录器而遇到 NullReferenceExceptions 。
现在,我知道这里有一些问题(甚至是答案),但我似乎找不到任何能指引我正确方向的问题。
我将不胜感激任何帮助(即使是“你这个笨蛋”就在这里!链接到我应该注意到的东西)。
I've been (happily) using Ninject for a while now with some basic scenarios, and would like to give it control of my logging. I noted the existence of the Ninject.Extensions.Logging namespace, and would like to use it, but I'm running into two issues:
- I want the logger to be initialized with the type of the class running it (as if I ran LogManager.GetLogger with the GetCurrentMethod().DeclaringType).
- I want to be able to easily mock, or "nullify" the logger for unit testing (i.e I don't want to have the logger work), without running into NullReferenceExceptions for not initializing the logger.
Now, I know there are some questions (and even answers) around here, but I couldn't seem to find any that pointed me in the right direction.
I'll appreciate any help (even a "you bone-head" it's here! Linking to something I should have noticed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好看一下单元测试。 https:// /github.com/ninject/ninject.extensions.logging/blob/master/src/Ninject.Extensions.Logging.Tests/Infrastruct/CommonTests.cs
Best you have a look at the unittests. https://github.com/ninject/ninject.extensions.logging/blob/master/src/Ninject.Extensions.Logging.Tests/Infrastructure/CommonTests.cs