首页 > Web开发 > 详细

log4net配置,正在用

时间:2015-06-12 16:50:17      阅读:264      评论:0      收藏:0      [点我收藏+]
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
    <appender name="errorAppender" type="log4net.Appender.RollingFileAppender">
        <filter type="log4net.Filter.LevelMatchFilter">
            <levelToMatch value="ERROR" />
        </filter>
        <filter type="log4net.Filter.DenyAllFilter" />
        <File value="Logs\err.log" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <datePattern value="yyyyMMdd" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
    </appender>
    <appender name="infoAppender" type="log4net.Appender.RollingFileAppender">
        <filter type="log4net.Filter.LevelMatchFilter">
            <levelToMatch value="INFO" />
        </filter>
        <filter type="log4net.Filter.DenyAllFilter" />
        <File value="Logs\info.log" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <datePattern value="yyyyMMdd" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
    </appender>
    <appender name="debugAppender" type="log4net.Appender.RollingFileAppender">
        <filter type="log4net.Filter.LevelMatchFilter">
            <levelToMatch value="DEBUG" />
        </filter>
        <filter type="log4net.Filter.DenyAllFilter" />
        <File value="Logs\debug.log" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <datePattern value="yyyyMMdd" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
        </layout>
    </appender>
    <root>
        <level value="ALL" />
        <appender-ref ref="errorAppender" />
        <appender-ref ref="infoAppender" />
        <appender-ref ref="debugAppender" />
    </root>
</log4net>


使用方法:

1. 程序启动时载入配置

 log4net.Config.XmlConfigurator.Configure(new FileInfo(AppDomain.CurrentDomain.BaseDirectory+@"configs\log4net.config"));

 web在 global.asax,win在 program.cs

2.使用

public static ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
Logger.Info(Exception ex);
Logger.Error();

 

log4net配置,正在用

原文:http://www.cnblogs.com/hualiu0/p/4571794.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!