iBatis.NET中log4不能用FILE-WATCH
经过Winform和Web项目测试,得出的结论是:IBatisNet.Common.Logging.Log4Net在配置configType属性时,不能使用FILE-WATCH的方式,使用INLINE的方式下可以正常使用。下面列出我的INLINE方式的配置文件。(Spring.NET+iBatis.NET日志+Spring.NET日志):
代码
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- log1:定义log4net节点和common节点组,以及该节点组下的logging节点 -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<!-- iBatis.log1:定义iBatis的日志配置 -->
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common"/>
</sectionGroup>
<!--
SP1:必须在.NET配置文件的<configSections>节点中注册这个类,
注册了这个节点处理器后,配置文件中的<spring>节点才能起
作用。(configSections必须是configuration下的第一个元素
否则会编译出错。)
context:容器资源列表(不能少,少了会出错)
objects:容器里面的对象列表(不能少,少了会出错)
-->
<sectionGroup name="spring">
<!--WebContextHandler是在Web项目中使用的-->
<!--section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/-->
<!--ContextHandler是在Web以外的项目中使用的-->
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<!--
SP2:配置Spring的容器,这样配置就不用在程序中显式地去创建
Spring的容器,从而降低了程序对Spring的耦合。
<context>节点的type属性是可选的,在Windows应用中,其默认值就是Spring.Context.Support.XmlApplicationContext
-->
<spring>
<context>
<!--SP3: 此处的配置文件是指包括了Spring.NET对象定义的XML文件,而非特指.config文件 -->
<resource uri="config://spring/objects"/>
<!--下面是引用.NET程序集内嵌资源时的URI语法:
assembly://<AssemblyName>/<NameSpace>/<ResourceName>
assembly://<程序集>/<命名空间>/<资源名称>
SP_Manual:加入不同项目的不同xml配置信息。如:
例:<resource uri="assembly://Piggy.NET.Web/Piggy.NET.Web/WebTest.xml"/>
-->
<resource uri="assembly://piggyWinForm/piggyWinFormTemplet/Objects.xml"/>
</context>
<!-- SP4:objects节点的xmlns元素是必需的,必须根据不同的应用添加不同的命名空间 -->
<objects xmlns="http://www.springframework.net"/>
</spring>
<!-- log2:实现log1中所定义的节点组common-->
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
<!-- otherwise BasicConfigurer.Configure is used -->
<!-- log4net configuration file is specified with key configFile-->
<arg key="configType" value="INLINE"/>
<!-- 0 to 6 (1 Debug 4 Error)>
<arg key="Level" value="ALL"/-->
</factoryAdapter>
</logging>
</common>
<!-- iBatis.log2:定义iBatis的日志配置 -->
<iBATIS>
<logging>
<logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="INLINE"/>
</logFactoryAdapter>
</logging>
</iBATIS>
<!-- log3:实现log1中所定义的节点log4net-->
<log4net debug="false">
<!--appender为不同日志输出的配置 -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="Logs\Application.log.txt"/>
<param name="datePattern" value="MM-dd HH:mm"/>
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="HttpTraceAppender" type="log4net.Appender.ASPNetTraceAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Log.txt"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Size"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<!-- 告诉日志的所使用的等级以及所使用的日志输出配置 -->
<!-- 下面是我自己改的,按日期生成日志的配置 -->
<appender name="RollingLogFileAppender_Piggy" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\ExceptionLog"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Date"/>
<param name="StaticLogFileName" value="false"/>
<param name="DatePattern" value="yyyyMMdd".log""/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingLogFileAppender_Piggy"/>
</root>
<!-- Set logging for Spring to INFO.
Logger names in Spring correspond to the namespace
加入下面这个logger可以在日志中自动输出Spring的INFO级别的信息-->
<logger name="Spring">
<level value="INFO" />
</logger>
<logger name="IBatisNet">
<level value="INFO" />
</logger>
<!-- Print only messages of level DEBUG or above in the packages -->
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.LazyLoadList">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.DaoSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.SqlMapSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.Common.Transaction.TransactionScope">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
<level value="DEBUG" />
</logger>
</log4net>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
<configuration>
<configSections>
<!-- log1:定义log4net节点和common节点组,以及该节点组下的logging节点 -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<!-- iBatis.log1:定义iBatis的日志配置 -->
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common"/>
</sectionGroup>
<!--
SP1:必须在.NET配置文件的<configSections>节点中注册这个类,
注册了这个节点处理器后,配置文件中的<spring>节点才能起
作用。(configSections必须是configuration下的第一个元素
否则会编译出错。)
context:容器资源列表(不能少,少了会出错)
objects:容器里面的对象列表(不能少,少了会出错)
-->
<sectionGroup name="spring">
<!--WebContextHandler是在Web项目中使用的-->
<!--section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/-->
<!--ContextHandler是在Web以外的项目中使用的-->
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<!--
SP2:配置Spring的容器,这样配置就不用在程序中显式地去创建
Spring的容器,从而降低了程序对Spring的耦合。
<context>节点的type属性是可选的,在Windows应用中,其默认值就是Spring.Context.Support.XmlApplicationContext
-->
<spring>
<context>
<!--SP3: 此处的配置文件是指包括了Spring.NET对象定义的XML文件,而非特指.config文件 -->
<resource uri="config://spring/objects"/>
<!--下面是引用.NET程序集内嵌资源时的URI语法:
assembly://<AssemblyName>/<NameSpace>/<ResourceName>
assembly://<程序集>/<命名空间>/<资源名称>
SP_Manual:加入不同项目的不同xml配置信息。如:
例:<resource uri="assembly://Piggy.NET.Web/Piggy.NET.Web/WebTest.xml"/>
-->
<resource uri="assembly://piggyWinForm/piggyWinFormTemplet/Objects.xml"/>
</context>
<!-- SP4:objects节点的xmlns元素是必需的,必须根据不同的应用添加不同的命名空间 -->
<objects xmlns="http://www.springframework.net"/>
</spring>
<!-- log2:实现log1中所定义的节点组common-->
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
<!-- otherwise BasicConfigurer.Configure is used -->
<!-- log4net configuration file is specified with key configFile-->
<arg key="configType" value="INLINE"/>
<!-- 0 to 6 (1 Debug 4 Error)>
<arg key="Level" value="ALL"/-->
</factoryAdapter>
</logging>
</common>
<!-- iBatis.log2:定义iBatis的日志配置 -->
<iBATIS>
<logging>
<logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="INLINE"/>
</logFactoryAdapter>
</logging>
</iBATIS>
<!-- log3:实现log1中所定义的节点log4net-->
<log4net debug="false">
<!--appender为不同日志输出的配置 -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="Logs\Application.log.txt"/>
<param name="datePattern" value="MM-dd HH:mm"/>
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="HttpTraceAppender" type="log4net.Appender.ASPNetTraceAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Log.txt"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Size"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<!-- 告诉日志的所使用的等级以及所使用的日志输出配置 -->
<!-- 下面是我自己改的,按日期生成日志的配置 -->
<appender name="RollingLogFileAppender_Piggy" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\ExceptionLog"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Date"/>
<param name="StaticLogFileName" value="false"/>
<param name="DatePattern" value="yyyyMMdd".log""/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingLogFileAppender_Piggy"/>
</root>
<!-- Set logging for Spring to INFO.
Logger names in Spring correspond to the namespace
加入下面这个logger可以在日志中自动输出Spring的INFO级别的信息-->
<logger name="Spring">
<level value="INFO" />
</logger>
<logger name="IBatisNet">
<level value="INFO" />
</logger>
<!-- Print only messages of level DEBUG or above in the packages -->
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.LazyLoadList">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.DaoSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.SqlMapSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.Common.Transaction.TransactionScope">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
<level value="DEBUG" />
</logger>
</log4net>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
原来是把log4net节点下的保存在“~\config\log4net.xml”中的,下面是iBatis.NET配置的日志不起作用的配置:
代码
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- log1:定义log4net节点和common节点组,以及该节点组下的logging节点 -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<!-- iBatis.log1:定义iBatis的日志配置 -->
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common"/>
</sectionGroup>
<!--
SP1:必须在.NET配置文件的<configSections>节点中注册这个类,
注册了这个节点处理器后,配置文件中的<spring>节点才能起
作用。(configSections必须是configuration下的第一个元素
否则会编译出错。)
context:容器资源列表(不能少,少了会出错)
objects:容器里面的对象列表(不能少,少了会出错)
-->
<sectionGroup name="spring">
<!--WebContextHandler是在Web项目中使用的-->
<!--section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/-->
<!--ContextHandler是在Web以外的项目中使用的-->
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<!--
SP2:配置Spring的容器,这样配置就不用在程序中显式地去创建
Spring的容器,从而降低了程序对Spring的耦合。
<context>节点的type属性是可选的,在Windows应用中,其默认值就是Spring.Context.Support.XmlApplicationContext
-->
<spring>
<context>
<!--SP3: 此处的配置文件是指包括了Spring.NET对象定义的XML文件,而非特指.config文件 -->
<resource uri="config://spring/objects"/>
<!--下面是引用.NET程序集内嵌资源时的URI语法:
assembly://<AssemblyName>/<NameSpace>/<ResourceName>
assembly://<程序集>/<命名空间>/<资源名称>
SP_Manual:加入不同项目的不同xml配置信息。如:
例:<resource uri="assembly://Piggy.NET.Web/Piggy.NET.Web/WebTest.xml"/>
-->
<resource uri="assembly://piggyWinForm/piggyWinFormTemplet/Objects.xml"/>
</context>
<!-- SP4:objects节点的xmlns元素是必需的,必须根据不同的应用添加不同的命名空间 -->
<objects xmlns="http://www.springframework.net"/>
</spring>
<!-- log2:实现log1中所定义的节点组common-->
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
<!-- otherwise BasicConfigurer.Configure is used -->
<!-- log4net configuration file is specified with key configFile-->
<arg key="configType" value="FILE-WATCH"/>
<arg key="configFile" value="~\config\log4net.xml"/>
<!-- 0 to 6 (1 Debug 4 Error)>
<arg key="Level" value="ALL"/-->
</factoryAdapter>
</logging>
</common>
<!-- iBatis.log2:定义iBatis的日志配置 -->
<iBATIS>
<logging>
<logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="FILE-WATCH"/>
<arg key="configFile" value="~\config\log4net.xml"/>
</logFactoryAdapter>
</logging>
</iBATIS>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
<configuration>
<configSections>
<!-- log1:定义log4net节点和common节点组,以及该节点组下的logging节点 -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<!-- iBatis.log1:定义iBatis的日志配置 -->
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common"/>
</sectionGroup>
<!--
SP1:必须在.NET配置文件的<configSections>节点中注册这个类,
注册了这个节点处理器后,配置文件中的<spring>节点才能起
作用。(configSections必须是configuration下的第一个元素
否则会编译出错。)
context:容器资源列表(不能少,少了会出错)
objects:容器里面的对象列表(不能少,少了会出错)
-->
<sectionGroup name="spring">
<!--WebContextHandler是在Web项目中使用的-->
<!--section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/-->
<!--ContextHandler是在Web以外的项目中使用的-->
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<!--
SP2:配置Spring的容器,这样配置就不用在程序中显式地去创建
Spring的容器,从而降低了程序对Spring的耦合。
<context>节点的type属性是可选的,在Windows应用中,其默认值就是Spring.Context.Support.XmlApplicationContext
-->
<spring>
<context>
<!--SP3: 此处的配置文件是指包括了Spring.NET对象定义的XML文件,而非特指.config文件 -->
<resource uri="config://spring/objects"/>
<!--下面是引用.NET程序集内嵌资源时的URI语法:
assembly://<AssemblyName>/<NameSpace>/<ResourceName>
assembly://<程序集>/<命名空间>/<资源名称>
SP_Manual:加入不同项目的不同xml配置信息。如:
例:<resource uri="assembly://Piggy.NET.Web/Piggy.NET.Web/WebTest.xml"/>
-->
<resource uri="assembly://piggyWinForm/piggyWinFormTemplet/Objects.xml"/>
</context>
<!-- SP4:objects节点的xmlns元素是必需的,必须根据不同的应用添加不同的命名空间 -->
<objects xmlns="http://www.springframework.net"/>
</spring>
<!-- log2:实现log1中所定义的节点组common-->
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
<!-- otherwise BasicConfigurer.Configure is used -->
<!-- log4net configuration file is specified with key configFile-->
<arg key="configType" value="FILE-WATCH"/>
<arg key="configFile" value="~\config\log4net.xml"/>
<!-- 0 to 6 (1 Debug 4 Error)>
<arg key="Level" value="ALL"/-->
</factoryAdapter>
</logging>
</common>
<!-- iBatis.log2:定义iBatis的日志配置 -->
<iBATIS>
<logging>
<logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="FILE-WATCH"/>
<arg key="configFile" value="~\config\log4net.xml"/>
</logFactoryAdapter>
</logging>
</iBATIS>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
"~\config\log4net.xml"中的代码是:
代码
<?xml version="1.0" encoding="utf-8" ?>
<!-- log3:实现log1中所定义的节点log4net-->
<log4net debug="false">
<!--appender为不同日志输出的配置 -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="Logs\Application.log.txt"/>
<param name="datePattern" value="MM-dd HH:mm"/>
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="HttpTraceAppender" type="log4net.Appender.ASPNetTraceAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Log.txt"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Size"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<!-- 告诉日志的所使用的等级以及所使用的日志输出配置 -->
<!-- 下面是我自己改的,按日期生成日志的配置 -->
<appender name="RollingLogFileAppender_Piggy" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\ExceptionLog"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Date"/>
<param name="StaticLogFileName" value="false"/>
<param name="DatePattern" value="yyyyMMdd".log""/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingLogFileAppender_Piggy"/>
</root>
<!-- Set logging for Spring to INFO.
Logger names in Spring correspond to the namespace
加入下面这个logger可以在日志中自动输出Spring的INFO级别的信息-->
<logger name="Spring">
<level value="INFO" />
</logger>
<logger name="IBatisNet">
<level value="INFO" />
</logger>
<!-- Print only messages of level DEBUG or above in the packages -->
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.LazyLoadList">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.DaoSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.SqlMapSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.Common.Transaction.TransactionScope">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
<level value="DEBUG" />
</logger>
</log4net>
<!-- log3:实现log1中所定义的节点log4net-->
<log4net debug="false">
<!--appender为不同日志输出的配置 -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="Logs\Application.log.txt"/>
<param name="datePattern" value="MM-dd HH:mm"/>
<param name="AppendToFile" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="HttpTraceAppender" type="log4net.Appender.ASPNetTraceAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\Log.txt"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Size"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<!-- 告诉日志的所使用的等级以及所使用的日志输出配置 -->
<!-- 下面是我自己改的,按日期生成日志的配置 -->
<appender name="RollingLogFileAppender_Piggy" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\ExceptionLog"/>
<param name="AppendToFile" value="true"/>
<param name="MaxSizeRollBackups" value="10"/>
<param name="MaximumFileSize" value="5MB"/>
<param name="RollingStyle" value="Date"/>
<param name="StaticLogFileName" value="false"/>
<param name="DatePattern" value="yyyyMMdd".log""/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingLogFileAppender_Piggy"/>
</root>
<!-- Set logging for Spring to INFO.
Logger names in Spring correspond to the namespace
加入下面这个logger可以在日志中自动输出Spring的INFO级别的信息-->
<logger name="Spring">
<level value="INFO" />
</logger>
<logger name="IBatisNet">
<level value="INFO" />
</logger>
<!-- Print only messages of level DEBUG or above in the packages -->
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.LazyLoadList">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.DaoSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.SqlMapSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.Common.Transaction.TransactionScope">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
<level value="DEBUG" />
</logger>
</log4net>
这是血的教训,希望大家不要在这问题上走弯路,具体原因没去考究了。希望知道的大侠指点一二。
原创作品出自努力偷懒,转载请说明文章出处:http://www.cnblogs.com/kfarvid/