Quartz.NET配置(Log4net)

最近有个任务关于服务调度,想起以前看过Quartz.NET调度任务非常棒。

今天小试Quartz.NET,前面配置Quartz.NET很轻松,控制台也输出了。但是想配合Log4net来做日志文件,怎么设置App.config文件都不行。

报如下错误:

Failed obtaining configuration for Common.Logging from configuration section 'common/logging'.

Unable to create type 'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211‘.

各程序集版本如下:

  • Quartz.NET (2.2.4.0)
  • Common.Logging.dll (2.1.2.0)(下载Quartz.NET时自带)
  • Common.Logging.Log4Net1211.dll (2.2.0.0)(重新从Nuget下载)
  • log4net.dll (1.2.11.0)(下载Common.Logging.Log4Net1211.dl时自带)

折腾了一个下午,没有搞出来。

看了下面地址中的思路,感觉也不对:

http://stackoverflow.com/questions/11368267/failed-obtaining-configuration-for-common-logging-from-configuration-section-co

回到家后,再想是不是Quartz.NET自带的Common.Logging.dll 的版本不正确。

重新升级到Common.Logging.dll(2.2.0.0),还自带出了Common.Logging.Core.dll(感觉对头了,哈哈)

不知道是不是Quartz.NET出了问题?

再测试,果然出现了日志文件,并且日志文件中有内容。

重新贴出各程序集版本:

  • Quartz.NET (2.2.4.0)
  • Common.Logging.dll (2.2.0.0)(升级后)
  • Common.Logging.Core.dll(2.2.0.0)
  • Common.Logging.Log4Net1211.dll (2.2.0.0)(重新从Nuget下载)
  • log4net.dll (1.2.11.0)(下载Common.Logging.Log4Net1211.dl时自带)

App.config配置文件如下:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <configuration>
  3   <configSections>
  4     <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  5     <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  6     <sectionGroup name="common">
  7       <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
  8     </sectionGroup>
  9   </configSections>
 10     <startup> 
 11         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
 12     </startup>
 13   <log4net>
 14     <appender name="InfoFileAppender" type="log4net.Appender.RollingFileAppender">
 15       <file value="log/" />
 16       <appendToFile value="true" />
 17       <param name="DatePattern" value="yyyyMMdd&quot;.txt&quot;" />
 18       <rollingStyle value="Date" />
 19       <maxSizeRollBackups value="100" />
 20       <maximumFileSize value="1024KB" />
 21       <staticLogFileName value="false" />
 22       <Encoding value="UTF-8" />
 23       <filter type="log4net.Filter.LevelRangeFilter">
 24         <param name="LevelMin" value="INFO" />
 25         <param name="LevelMax" value="INFO" />
 26       </filter>
 27       <layout type="log4net.Layout.PatternLayout">
 28         <conversionPattern value="%date %-5level %logger  - %message%newline" />
 29       </layout>
 30     </appender>
 31     <appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender">
 32       <file value="log/error.txt" />
 33       <appendToFile value="true" />
 34       <rollingStyle value="Size" />
 35       <maxSizeRollBackups value="100" />
 36       <maximumFileSize value="10240KB" />
 37       <staticLogFileName value="true" />
 38       <Encoding value="UTF-8" />
 39       <filter type="log4net.Filter.LevelRangeFilter">
 40         <param name="LevelMin" value="WARN" />
 41         <param name="LevelMax" value="FATAL" />
 42       </filter>
 43       <layout type="log4net.Layout.PatternLayout">
 44         <conversionPattern value="%date %-5level %logger - %message%newline" />
 45       </layout>
 46     </appender>
 47     <root>
 48       <level value="INFO" />
 49       <appender-ref ref="InfoFileAppender" />
 50       <appender-ref ref="ErrorFileAppender" />
 51     </root>
 52   </log4net>
 53   <common>
 54     <logging>
 55      <!-- <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
 56         <arg key="showLogName" value="true"/>
 57         <arg key="showDataTime" value="true"/>
 58         <arg key="level" value="INFO"/>
 59         <arg key="dateTimeFormat" value="HH:mm:ss:fff"/>
 60       </factoryAdapter>-->
 61       <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211">
 62         <arg key="configType" value="INLINE" />
 63       </factoryAdapter>
 64     </logging>
 65   </common>
 66   <quartz>
 67     <add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzScheduler" />
 68     <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
 69     <add key="quartz.threadPool.threadCount" value="10" />
 70     <add key="quartz.threadPool.threadPriority" value="2" />
 71     <add key="quartz.jobStore.misfireThreshold" value="60000" />
 72     <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
 73     <!-- sample configuration based db provider -->
 74     <add key="quartz.dbprovider.customProvider.productName" value="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" />
 75     <add key="quartz.dbprovider.customProvider.assemblyName" value="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 76     <add key="quartz.dbprovider.customProvider.connectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 77     <add key="quartz.dbprovider.customProvider.commandType" value="System.Data.SqlClient.SqlCommand, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 78     <add key="quartz.dbprovider.customProvider.parameterType" value="System.Data.SqlClient.SqlParameter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 79     <add key="quartz.dbprovider.customProvider.commandBuilderType" value="System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 80     <add key="quartz.dbprovider.customProvider.parameterDbType" value="System.Data.SqlDbType, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 81     <add key="quartz.dbprovider.customProvider.parameterDbTypePropertyName" value="SqlDbType" />
 82     <add key="quartz.dbprovider.customProvider.parameterNamePrefix" value="@" />
 83     <add key="quartz.dbprovider.customProvider.exceptionType" value="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 84     <add key="quartz.dbprovider.customProvider.useParameterNamePrefixInParameterCollection" value="true" />
 85     <add key="quartz.dbprovider.customProvider.bindByName" value="true" />
 86     <add key="quartz.dbprovider.customProvider.dbBinaryTypeName" value="Image" />
 87   </quartz>
 88   <runtime>
 89     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 90       <dependentAssembly>
 91         <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
 92         <bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
 93       </dependentAssembly>
 94       <dependentAssembly>
 95         <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
 96         <bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.11.0" />
 97       </dependentAssembly>
 98     </assemblyBinding>
 99   </runtime>
100 </configuration>
配置文件

 

posted @ 2014-10-31 20:36  无眠  阅读(2862)  评论(0编辑  收藏  举报