1 、[assembly: log4net.Config.XmlConfigurator(ConfigFile = "web.config", Watch = true)]  写到自定义的Log类中的AssemblyInfo.cs中

<configSections>

        <!-- 添加log4net配置节 -->
        <section name="log4net"   type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
    </configSections>

    <!-- 设置log4net配置节 -->    
    <log4net>
        <!--输出到文件-->
        <appender name="rollingFile"  type="log4net.Appender.RollingFileAppender,log4net" >
            <param name="File" type="" value="c:\testlog\log.txt" />
            <param name="AppendToFile" value="true" />
            <param name="Encoding" value="utf-8" />

<param name="StaticLogFileName" value="true" />


            <!-- 滚动方式:按日期 -->
            <param name="RollingStyle" value="Date" />
            <param name="DatePattern" value="yyyyMMdd" />

            <!-- 滚动方式:按日志大小
            <param name="RollingStyle" value="Size"/>
            <param name="MaxSizeRollBackups" value="100"/>
            <param name="MaximumFileSize" value="2MB"/>        
            -->

           <layout type="log4net.Layout.PatternLayout,log4net">
                <param name="Header" value="" />
                <param name="Footer" value="" />
                <param name="ConversionPattern" value="%n%date [线程ID:%thread] 文件:%file [%line] %-5level %logger [优先级别:%property{NDC}] ---- %n 【错误信息】 %m%n%n" />
            </layout>
        </appender>

        <root>
            <level value="ALL"/>
            <appender-ref ref="rollingFile"/>
        </root>
    </log4net>

  

posted on 2015-11-23 12:02  广  阅读(2353)  评论(0编辑  收藏  举报