【问题标题】:Logging with Quartz.net使用 Quartz.net 进行日志记录
【发布时间】:2011-03-01 09:43:54
【问题描述】:

我会无耻地声明我对 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>

【问题讨论】:

  • 你能提供你得到的错误吗?

标签: logging log4net quartz.net


【解决方案1】:

试试这个配置:

    <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>

【讨论】:

  • 我知道这已经很晚了,但是%d%t%-5p 等...ConversionPattern 布局中的占位符是什么?还有其他可用的吗?是否有任何关于此的文档?
  • @SmartDev:你可以找到他们记录在案的here,如果你现在还没有的话。
猜你喜欢
  • 2012-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多