首页 > 代码库 > Common.Logging log4net Common.Logging.Log4Net 配置
Common.Logging log4net Common.Logging.Log4Net 配置
1、log4net 单独配置
log4net支持多种格式的日志输出,我这里只配置输出到本地的txt文件这种格式。
<log4net> <root> <appender-ref ref="RollingFileAppender" /> </root> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="http://www.mamicode.com//Data//Log//Log.txt" /> <param name="AppendToFile" value="http://www.mamicode.com/true" /> <param name="MaxSizeRollBackups" value="http://www.mamicode.com/10" /> <param name="MaximumFileSize" value="http://www.mamicode.com/5MB" /> <param name="RollingStyle" value="http://www.mamicode.com/Size" /> <param name="StaticLogFileName" value="http://www.mamicode.com/true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="http://www.mamicode.com/%n[时间]:%d%n[级别]:%p%n[内容]:%m%n" /> </layout> </appender> </log4net>
2、Common.Logging 配置
<configSections> <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/> </sectionGroup> </configSections> <common> <logging> <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> <arg key="showLogName" value=http://www.mamicode.com/"true"/> <arg key="showDataTime" value=http://www.mamicode.com/"true"/> <arg key="level" value=http://www.mamicode.com/"INFO"/> <arg key="dateTimeFormat" value=http://www.mamicode.com/"HH:mm:ss:fff"/> </factoryAdapter> </logging> </common>
3、Common.Logging+log4net+ Common.Logging.Log4Net配置
在联合使用Common.Logging和log4net日志组件时需要注意组件之间的版本是否匹配。
参考:http://stackoverflow.com/questions/8172623/how-to-configure-logging-in-spring-net-using-log4net
组件下载:https://github.com/net-commons/common-logging/tree/2.3.0.RC1
<configSections> <sectionGroup name="common"> <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/> </sectionGroup> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> </configSections> <common> <logging> <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4Net1210"> <arg key="configType" value=http://www.mamicode.com/"INLINE" /> </factoryAdapter> </logging> </common> <log4net> <root> <appender-ref ref="RollingFileAppender" /> </root> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value=http://www.mamicode.com/"%date [%thread] %-5level %logger %ndc - %message%newline" /> </layout> </appender> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value=http://www.mamicode.com/"..\\Data\\Log\\Log.txt" /> <param name="AppendToFile" value=http://www.mamicode.com/"true" /> <param name="MaxSizeRollBackups" value=http://www.mamicode.com/"10" /> <param name="MaximumFileSize" value=http://www.mamicode.com/"5MB" /> <param name="RollingStyle" value=http://www.mamicode.com/"Size" /> <param name="StaticLogFileName" value=http://www.mamicode.com/"true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value=http://www.mamicode.com/"%n[时间]:%d%n[级别]:%p%n[内容]:%m%n" /> </layout> </appender> </log4net>
4、输出效果截图
Common.Logging log4net Common.Logging.Log4Net 配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。