使用 Quartz.net 记录日志

发布于 2024-09-05 00:43:56 字数 1550 浏览 7 评论 0原文

我会无耻地声明我对 Log4Net 的经验很少。我刚刚安装了它,但它不会从 Quartz.net(一个调度库)捕获日志事件。显然 Quartz.net 使用 Commons Logging,需要配置为指向我的 Log4Net 设置。不幸的是,它似乎不起作用。感谢帮助:

  <configSections>
    ...
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <section name="commonLogging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
  </configSections>
  <!-- Log4net error handling -->
  <log4net>
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
      <param name="File" value="Admin/LabSlice.log" />
      <param name="AppendToFile" value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c  %m%n" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="LogFileAppender" />
    </root>
  </log4net>
  <!-- Commons logging (Quart.net logs) -->
  <commonLogging>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
        <arg key="configType" value="INLINE" />
      </factoryAdapter>
    </logging>
  </commonLogging>

I will shamelessly state that I have little experience with Log4Net. I only just installed it, but it won't capture log events from Quartz.net, which is a scheduling library. Apparently Quartz.net uses Commons Logging and that needs to be configured to point to my Log4Net settings. Unfortunately, it doesn't seem to work. Help is appreciated:

  <configSections>
    ...
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <section name="commonLogging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
  </configSections>
  <!-- Log4net error handling -->
  <log4net>
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
      <param name="File" value="Admin/LabSlice.log" />
      <param name="AppendToFile" value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c  %m%n" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="LogFileAppender" />
    </root>
  </log4net>
  <!-- Commons logging (Quart.net logs) -->
  <commonLogging>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
        <arg key="configType" value="INLINE" />
      </factoryAdapter>
    </logging>
  </commonLogging>

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

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

发布评论

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

评论(1

内心激荡 2024-09-12 00:43:56

试试这个配置:

    <configSections>
      ....
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
      <section name="quartz" type="System.Configuration.NameValueSectionHandler, 
               System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <sectionGroup name="common">
        <section name="logging" type="Common.Logging.ConfigurationSectionHandler,
                 Common.Logging"/>
      </sectionGroup>
    </configSections>

    <appSettings>
      <add key="log4net.Internal.Debug" value="false"/>
    </appSettings>

    <common>
      <logging>
        <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,
                        Common.Logging.Log4Net">
          <arg key="configType" value="INLINE"/>
          <arg key="configFile" value="Trace/application.log.txt"/>
          <arg key="level" value="ALL" />
        </factoryAdapter>
      </logging>
    </common>

    <log4net>
      <appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
        <file value="Trace/application.log.txt"/>
        <appendToFile value="true"/>
        <maximumFileSize value="1024KB"/>
        <rollingStyle value="Size"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%d{HH:mm:ss} [%t] %-5p %c - %m%n"/>
        </layout>
      </appender>

      <root>
        <level value="ALL"/>
        <appender-ref ref="GeneralLog"/>
      </root>

    </log4net>

Try this configuration:

    <configSections>
      ....
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
      <section name="quartz" type="System.Configuration.NameValueSectionHandler, 
               System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <sectionGroup name="common">
        <section name="logging" type="Common.Logging.ConfigurationSectionHandler,
                 Common.Logging"/>
      </sectionGroup>
    </configSections>

    <appSettings>
      <add key="log4net.Internal.Debug" value="false"/>
    </appSettings>

    <common>
      <logging>
        <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,
                        Common.Logging.Log4Net">
          <arg key="configType" value="INLINE"/>
          <arg key="configFile" value="Trace/application.log.txt"/>
          <arg key="level" value="ALL" />
        </factoryAdapter>
      </logging>
    </common>

    <log4net>
      <appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
        <file value="Trace/application.log.txt"/>
        <appendToFile value="true"/>
        <maximumFileSize value="1024KB"/>
        <rollingStyle value="Size"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%d{HH:mm:ss} [%t] %-5p %c - %m%n"/>
        </layout>
      </appender>

      <root>
        <level value="ALL"/>
        <appender-ref ref="GeneralLog"/>
      </root>

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