nHibernate 禁用我的 log4net 日志

发布于 2024-08-19 20:31:31 字数 2575 浏览 8 评论 0原文

因此,我们有一个小的 ETL 应用程序,在更新方面存在一些问题。在下午的冲刺中,使用 nHibernate 很好地解决了这个问题。但是这个应用程序依赖 log4net 根据命令行开关将日志记录输出推送到几个不同的目的地。一旦我们将 nHibernate 封装到应用程序中,它就可以完美地进行 ETL。但日志功能完全失败。从调试器的角度来看,我们的任何记录器都禁用了所有 log4net 级别。

这是 log4net 配置:

<log4net>
  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="import-" />
    <staticLogFileName value="false" />
    <appendToFile value="false" />
    <rollingStyle value="Date" />
    <maxSizeRollBackups value="5" />
    <datePattern value="yyyyMMdd-HHmm&quot;.log&quot;" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %-5level - %message%newline" />
    </layout>
  </appender>

  <appender name="Console" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5level : %message%newline" />
    </layout>
  </appender>

  <appender name="Email" type="log4net.Appender.SmtpAppender">
    <to value="[email protected]" />
    <from value="[email protected]" />
    <subject value="Cte Importer Error" />
    <smtpHost value="smtp.example.com" />
    <bufferSize value="512" />
    <lossy value="false" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%newline%date %-5level : %message%newline%newline%newline" />
    </layout>
  </appender>

  <root>
    <level value="ALL" />
  </root>

  <logger name="Console">
    <level value="INFO" />

    <appender-ref ref="Console" />
  </logger>
  <logger name="File">
    <level value="INFO" />
    <appender-ref ref="RollingFile" />
  </logger>
  <logger name="DebugConsole">
    <level value="DEBUG" />
    <appender-ref ref="Console" />
  </logger>
  <logger name="DebugFile">
    <level value="DEBUG" />
    <appender-ref ref="RollingFile" />
  </logger>
  <logger name="EmailErrors">
    <level value="ERROR" />
    <appender-ref ref="Email" />
  </logger>
</log4net>

不确定还有哪些其他代码会有帮助,但我很乐意发布此应用程序中的其他内容。

So, we had a little ETL app that had some issues with updates. Which were nicely solved in an afternoon sprint with nHibernate. But this app relied upon log4net to push logging output to a few different destinations based upon command line switches. Once we got nHibernate wrapped into the app, it ETL'd flawlessly. But the logging functions failed completely. From the debugger's point of view, any of our loggers have all log4net's levels disabled.

Here's the log4net config:

<log4net>
  <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="import-" />
    <staticLogFileName value="false" />
    <appendToFile value="false" />
    <rollingStyle value="Date" />
    <maxSizeRollBackups value="5" />
    <datePattern value="yyyyMMdd-HHmm".log"" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %-5level - %message%newline" />
    </layout>
  </appender>

  <appender name="Console" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5level : %message%newline" />
    </layout>
  </appender>

  <appender name="Email" type="log4net.Appender.SmtpAppender">
    <to value="[email protected]" />
    <from value="[email protected]" />
    <subject value="Cte Importer Error" />
    <smtpHost value="smtp.example.com" />
    <bufferSize value="512" />
    <lossy value="false" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%newline%date %-5level : %message%newline%newline%newline" />
    </layout>
  </appender>

  <root>
    <level value="ALL" />
  </root>

  <logger name="Console">
    <level value="INFO" />

    <appender-ref ref="Console" />
  </logger>
  <logger name="File">
    <level value="INFO" />
    <appender-ref ref="RollingFile" />
  </logger>
  <logger name="DebugConsole">
    <level value="DEBUG" />
    <appender-ref ref="Console" />
  </logger>
  <logger name="DebugFile">
    <level value="DEBUG" />
    <appender-ref ref="RollingFile" />
  </logger>
  <logger name="EmailErrors">
    <level value="ERROR" />
    <appender-ref ref="Email" />
  </logger>
</log4net>

Not sure what other code would help, but I'm happy to post anything else from this app.

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

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

发布评论

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

评论(2

や三分注定 2024-08-26 20:31:31

您使用什么版本的 NHibernate?早于 1.0-RC1 的版本会在内部打开日志记录。在 1.0-RC1 中,他们对此进行了更改,因此您必须手动调用 log4net.XmlConfigurator.Configure()。这样做是为了让开发人员更好地控制日志记录。

What version of NHibernate are you using? Builds older than 1.0-RC1 turned logging on internally. In 1.0-RC1 they changed this so you have to manually call log4net.XmlConfigurator.Configure(). This was done to give developers more control over logging.

守护在此方 2024-08-26 20:31:31

您可以尝试在 log4net 中打开内部调试:请参阅以下链接中的本节:

“如何启用 log4net 内部调试?”

http://logging.apache.org/log4net/release/faq.html

You could try turning on the internal debugging in log4net: See this section in the following link:

"How do I enable log4net internal debugging?"

http://logging.apache.org/log4net/release/faq.html

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