我的解决方案下的log4net问题

发布于 2024-11-10 03:25:41 字数 1849 浏览 2 评论 0原文

在我的 VS2010 解决方案下,我遇到这种情况:

  • WEBSITE
  • Library1
  • Library2

在 global.asax.cs 上,我使用以下方法初始化 log4net 配置:

private static log4net.ILog _logger = log4net.LogManager.GetLogger("globalASAX");

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    log4net.Config.XmlConfigurator.Configure();
    _logger.Info("[APPLICATION START] " + DateTime.Now.ToString());
} 

它工作正常,并且应用程序启动消息在 log.txt 文件上正确可用。当我尝试在 DLL Library1 或 Library2 上可用的类上使用日志时,就会出现问题。

我添加了行:

private static log4net.ILog _logger = log4net.LogManager.GetLogger(typeof(ImageRepository));

但是当我尝试所有 _logger.error("blabla") 时,日志文件上没有任何反应; _logger 的所有属性均为 false(即 isdebugenable=false)。我该如何解决这个问题?我按照此处提供的说明进行操作:

http://logging.apache.org/log4net/ release/manual/configuration.html

log4net 的配置位于 web.config 文件下:

<log4net>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
        <file type="log4net.Util.PatternString">
            <conversionPattern value="log\explorer-log-%date{ yyyy.MM.dd.HH.mm.ss}-[%processid].log"/>
        </file>
        <appendToFile value="true"/>
        <maximumFileSize value="1024KB"/>
        <maxSizeRollBackups value="5"/>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date %level %logger - %message%newline"/>
        </layout>
    </appender>
    <root>
        <level value="DEBUG"/>
        <appender-ref ref="RollingFile"/>
    </root>
</log4net>

有人可以帮助我吗? 谢谢, 安德里亚

Under my VS2010 solution I've this situation:

  • WEBSITE
  • Library1
  • Library2

On global.asax.cs I initialize the log4net configuration using:

private static log4net.ILog _logger = log4net.LogManager.GetLogger("globalASAX");

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    log4net.Config.XmlConfigurator.Configure();
    _logger.Info("[APPLICATION START] " + DateTime.Now.ToString());
} 

It works fine and Application start message is correclty available on log.txt file. The problem happens when I try to use log something on the classes available on DLL Library1 or Library2.

I added the row:

private static log4net.ILog _logger = log4net.LogManager.GetLogger(typeof(ImageRepository));

but when I try to all the _logger.error("blabla") nothing happens on log file; all properties of _logger are false (i.e. isdebugenable=false). How can I fix that? I followed the instruction available here:

http://logging.apache.org/log4net/release/manual/configuration.html

the configuration of log4net is under web.config file:

<log4net>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
        <file type="log4net.Util.PatternString">
            <conversionPattern value="log\explorer-log-%date{ yyyy.MM.dd.HH.mm.ss}-[%processid].log"/>
        </file>
        <appendToFile value="true"/>
        <maximumFileSize value="1024KB"/>
        <maxSizeRollBackups value="5"/>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date %level %logger - %message%newline"/>
        </layout>
    </appender>
    <root>
        <level value="DEBUG"/>
        <appender-ref ref="RollingFile"/>
    </root>
</log4net>

anyone can help me?
thanks,
Andrea

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩物 2024-11-17 03:25:41

我怀疑 log4net 找不到您的类型 ImageRepository 的记录器。作为快速检查,创建一个命名记录器并尝试调用它。

private static log4net.ILog _logger = log4net.LogManager.GetLogger("FooLog");

和配置

<root>
    <level value="DEBUG"/>
    <appender-ref ref="RollingFile"/>
</root>
<logger name="FooLog">
    <level value="DEBUG"/>
    <appender-ref ref="RollingFile"/>
</logger>

I suspect log4net cannot find the logger for your type ImageRepository. As a quick check create a named logger and try calling it.

private static log4net.ILog _logger = log4net.LogManager.GetLogger("FooLog");

And config

<root>
    <level value="DEBUG"/>
    <appender-ref ref="RollingFile"/>
</root>
<logger name="FooLog">
    <level value="DEBUG"/>
    <appender-ref ref="RollingFile"/>
</logger>
苍白女子 2024-11-17 03:25:41

理论上这应该可行(我相信你知道)。然而,一般来说,当您没有将任何内容记录到文件中时,需要检查两个区域。我要检查的第一个区域是文件附加器本身。文本文件可以被锁定,这可能会导致消息丢失。我要检查的另一件事是确保 log4net 在库中正确初始化。应该是的,不过检查一下也没什么坏处。如果这些解决方案都没有帮助,请尝试打开 log4net 本身的调试以查看出现哪些错误消息。以下链接向您展示如何打开这些消息:

http://haacked .com/archive/2006/09/27/Log4Net_Troubleshooting.aspx

In theory this should work (as I'm sure you are aware). In general, however, there are two areas to check when you don't get anything logged to a file. The first area I would check would be the file appender itself. Text files can be locked, which can cause messages to be lost. The other thing I would check is to be sure that log4net is properly initialized in the library. It should be, but it doesn't hurt to check. If neither of these solutions help, try turning on the debugging of log4net itself to see what error messages are coming up. Here is a link that shows you how to turn on those messages:

http://haacked.com/archive/2006/09/27/Log4Net_Troubleshooting.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文