Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

log4net - Logging with Quartz.net

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...