深入学习common.logging
若只需要使用log输出到控制台:
.config配置如下:
<configSections>
<sectionGroup name="common">
<!--1.此Adapter只输出到控制台-->
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<!--1.此Adapter只输出到控制台-->
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="DEBUG" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
二、使用common.logging.log4net adapter输出到log4net
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="common">
<!--1.此Adapter只输出到控制台-->
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<common>
<logging>
<!--1.此Adapter只输出到控制台-->
<!--<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="DEBUG" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>-->
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger %ndc - %message%newline" />
</layout>
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender, log4net">
<param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
<param name="File" value="App_Data/log/" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value="yyyy-MM-dd.'log'" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="5MB" />
<param name="RollingStyle" value="Date" />
<!--Size ==- Date-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n%newline" />
</layout>
</appender>
<root> <!--设置默认日志器-->
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<logger name="MyApp.DataAccessLayer">
<level value="DEBUG" />
</logger>
<logger name="RollingLogFileAppender">
<level value="INFO"></level>
</logger>
</log4net>
</configuration>