我的log4net曾经工作过,并且不确定它何时停止工作,但今天当我将应用程序放到生产服务器上时,我注意到没有生成日志,这就是为什么,有人知道如何解决这个问题?
log4net: log4net assembly [log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821]. Loaded from [C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\webservices\5da47f19\dc42c9c9\assembly\dl3\8f8d7275\00beb281_ec53c601\log4net.DLL]. (.NET Runtime [2.0.50727.4927] on Microsoft Windows NT 6.1.7600.0)
log4net: DefaultRepositorySelector: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [ISDS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [MyASM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\webservices\5da47f19\dc42c9c9\assembly\dl3\38092252\c8d83679_5e56ca01\ISDS.DLL]
log4net: DefaultRepositorySelector: Assembly [MyASM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] **does not have a RepositoryAttribute specified**.
log4net: DefaultRepositorySelector: Assembly [MyASM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
答案 0 :(得分:4)
发生这种情况的一个原因是程序集的加载顺序发生变化,并且在log4net配置之前有一个日志引用。
您的应用程序中的log4net配置在哪里?如果是以编程方式进行,请跟踪它并确保在第一次调用GetLogger
之前配置了log4net。我倾向于在配置log4net之后抛出日志引用,以确保这一点。
XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));
log = LogManager.GetLogger(...));