Log4net配置文件一般配置

 

配置文件一般配置

<?xml version="1.0"?>
<configuration>
    
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
    </configSections>
    <log4net>
        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="[时间]:%d%n[级别]:%p%n[内容]:%m%n%n"/>
            </layout>
        </appender>
        <appender name="FileAppender" type="log4net.Appender.FileAppender">
            <param name="file" value="Log.log"/>
            <param name="appendToFile" value="true"/>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="[时间]:%d%n[级别]:%p%n[内容]:%m%n%n"/>
            </layout>
        </appender>
        <!--<root>
      <level value="INFO"></level>
      <appender-ref ref="FileAppender"></appender-ref>
      <appender-ref ref="ConsoleAppender"></appender-ref>
    </root>-->
        <logger name="MyLogger">
            <level value="INFO"/>
            <appender-ref ref="FileAppender"/>
            <appender-ref ref="ConsoleAppender"/>
        </logger>
    </log4net>
    <appSettings>
        <add key="currentNum" value="0"/>
    </appSettings>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

 

 调用方式 

   先添加引用

    

using log4net.Config;
using log4net;


public
static ILog log = LogManager.GetLogger("MyLogger"); public static void InitLog() { XmlConfigurator.Configure(); log.Info("--Main开始--"); }

 

 

 

 

posted @ 2013-11-05 17:56  兴想事成  阅读(152)  评论(0编辑  收藏  举报