使用log4net的在应用程序的WebForms记录Ninject扩展 [英] Use log4net with Ninject logging extensions in WebForms application
问题描述
有些挣扎,我设法得到一个使用Ninject记录延伸和log4net的日志记录框架工作ASP.NET web表单应用程序之后。 (学分这个博客为基本)。
但是,我对如何继续的一些问题。
首先,我需要做的ILogger财产公开,因为它仍然为空,如果它是私有或保护。
所以现在我有这样的:
[注入]
保护ILogger _logger {搞定;组; }
而不是:
私有静态只读的ILog记录仪= LogManager.GetLogger(MethodBase.GetCurrentMethod()DeclaringType);
我可以住在一起,但它似乎很奇怪。
另一件事是ThreadContext该log4net的使用,以填补当前上下文。我仍然可以使用它像这样
使用(ThreadContext.Stacks [NDC。按(MethodBase.GetCurrentMethod()。名称))
{
_logger.Info(测试);
}
但offcourse夺一切,我刚刚添加的抽象..
所以,我在找其他人可能有这种情况的一些经验/最佳实践。
其他的问题:我已经升级到log4net的这1.2.11.0中的NuGet目前的版本,现在Ninject.Logging.log4net被打破,因为它预期的版本1.2.10.0 ...有没有办法解决呢?
其他的问题:我已经升级到log4net的其中1.2.11.0是
当前版本的NuGet,现在Ninject.Logging.log4net被打破
因为它需要版本1.2.10.0 ...是有办法解决这个问题?
块引用>你有没有尝试修复允许版本的[XX]在Packages.config文件?
<包ID =log4net的版本=1.2.10allowedVersions =[1.2.10]/> />
这将prevent旁边的更新升级到1.2.11以上。
http://docs.nuget.org/docs/reference/versioning
After some struggling I managed to get a working ASP.NET webforms application that uses the Ninject logging extension and log4net as logging framework. (credits to this blog for the basics). But I have some questions on how to continue.
First, I needed to make the ILogger property public, because it remained null if it was private or protected. So now I have this:
[Inject] protected ILogger _logger { get; set; }
Instead of:
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
I can live with it, but it seems strange.
Another thing is the ThreadContext that log4net uses to fill the current context. I can still use it like this
using (ThreadContext.Stacks["NDC"].Push(MethodBase.GetCurrentMethod().Name)) { _logger.Info("test"); }
But offcourse that takes away all the abstraction that I just added.. So I'm looking for some experiences / best practices that other people may have with this scenario.
Additional question: I've upgraded log4net to 1.2.11.0 which is the current version in NuGet, and now Ninject.Logging.log4net is broken because it expects version 1.2.10.0 ... is there a way to fix that?
解决方案Additional question: I've upgraded log4net to 1.2.11.0 which is the current version in NuGet, and now Ninject.Logging.log4net is broken because it expects version 1.2.10.0 ... is there a way to fix that?
Did you try to fix the allowed versions with [xx] in the Packages.config file ?
<package id="log4net" version="1.2.10" allowedVersions="[1.2.10]" /> />
It will prevent next updates to upgrade to 1.2.11 or more.
http://docs.nuget.org/docs/reference/versioning
这篇关于使用log4net的在应用程序的WebForms记录Ninject扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!