1.简介
common logging是一个通用日志接口,log4net是一个具体实现. common logging可以把输出连接到其他非log类上, 如EntLib的日志、NLog等

2.使用
接下来介绍的是和log4net一起使用的介绍.
#程序中需要引入的:
#Common.Logging.dll
#Common.Logging.Log4Net.dll
#log4net.dll

Common.Logging.ILog logger = Common.Logging.LogManager.GetLogger(Assembly.GetExecutingAssembly().GetName().Name);
logger.Info("shutdown quartz.");
logger.Debug("shutdown quartz.");

3.配置
在app.config或者web.config中,加入:
    <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.Log4Net">
                <arg key="configType" value="INLINE" />
            </factoryAdapter>
        </logging>
    </common>
    
    <log4net>
        <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
            <param name="File" value="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>
        <root>
            <level value="DEBUG" />
            <appender-ref ref="LogFileAppender" />
        </root>
    </log4net>
 
关于log4net的详细设置,请参考http://blog.sina.com.cn/s/blog_ad0672d60101ko49.html

posted on 2017-03-02 14:29  心丨魔  阅读(436)  评论(0编辑  收藏  举报