log4net日志的简单配置

说起来log4net,我一直都知道这个的存在,但实际在项目中还真是没有去自己写过的那,这一次我在项目完成后并没有着急下一个项目的开始,于是突然想起来是否添加一个日志的编写,于是开始了log4net的总结,下面就简单的总结一下自己在添加log4net时间注意的。

1.首先我们在添加log4net之前需要添加其引用,这里就通过在web网站的引用添加其nuget包引用来添加,如下所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdgAAACQCAIAAAAkx+17AAAgAElEQVR4nO2d+3cTR57o9cv+F/ec2UwCGLDB2Lxf8vvFy5YsCwQ2GPmNXxhjhBDc3GvfWebu3JnMZDezioWDjHkms7vnZGdkeUfj7OxyDgOTySShJZ8kk+wjOyQhk0nHgAMh+P5Q/ajqrupuyZK7bb46nx9suVXdXVX98Vffrq6yHS612UpbfT2erOWerlNnfAR9ruW24ibizRP+0wP+00fcK5a5W2qX24qaTg9071tmU7yWO7tO9XftXWYraTjh7xvw9w2c7DveVb3MZj/oO9p/otmZZSs41HNsoOfYQE/foe22ov19A11H+zu6j7Z17t+Iynim0nHQ695/0Onev8fp3rHHWb5jT1HZju1F5Zu3F6/fYs/bsHV1/sbs3HVZOXnPLV/1bFb2M0tX/OUSwyw1yEoA0OaZZdmI7y7L/m5Wznezcp7Nynl2+SrEcytWPbdi9ZKVuUtW5i7Nzl2avWZp9ppl2WuW5eQty8nLysnLWpWXtSpfzfJV+ctXK1irwQqJ3HVqVuauW7lGl/US2WvWZ+etz87boCbHCPmIjQpW5W9ctTY1Nq3WZR1i84Ji0+q1m2yNJTZbSesJf59ruS3L3XfCfwZDevM0SUuRreyQ/2jtcltRU2DAHxg4GTh+MtBRt3yZq/e4L3Dcd6rfd6q/scRW1HTshP/YiZN9A76jgohP7C+02QoaBQsfG+jpO7TNVujpO97Ze6yj62jrke6mtiOHm9sbDu8v/M4z22saJBGXVe0uKquSRbx+y+r8jStz1y3LXvPc8lXfXZakiI0a2fzrHLA4zyzTcvFzy1c9t2L1EsnFK0UX5xhz8SqjIiZ0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Q+merx6zS3dhPPHyBiAqpq0/gy0CQUG6qnWBQmvZbf1Mg/KK4QLNpT9Fq8y1K2FF0gv0s5NqJzK38l3veGp6Sl2JiXPVayuD2rcGZFKT8yGNOZ+UV97sSVKTQQuS+jraaZmhALMXTizB3R65xaJnXv2i1CmX9SPQuo9onoNjGtT6Z8/DrNTUbE7NbMNCBiAsuKWPFlDYmY/CarJ2IiasOuarGLy6sOs7bEEbehXF1pErFqAkOaVellKn5VnoJcsjrApJ47Q8Tk3JiGWs2IiI2dOHNH1Dqnl5msiClVJ5evrg3Gieg2MaVPzuX4tZp7EYtY7xHniE/c0jX8/wFkGJM11pny0QAAAABJRU5ErkJggg==" alt="" />

添加引用完成后,我们打开web网站引用即可看到存在log4net,这就意味着我们已经添加log4net引用成功。

2.下面我们就打开web网站的Properties文件夹下的AssemblyInfo.cs类文件,然后添加文件的配置:

            [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log.config", Watch = true)]   

3.ConfigFile是指定log4net使用.config文件来读取配置信息,这里我新创建了一个config文件,专业用来配置log4net。也可以将其配置在web.config文件中,在log.config中,将其log4net文件配置在<configuration>节点中.

             <?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web> <log4net>
<!--定义输出到文件中-->
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<!--定义文件存放位置-->
<file value="~logs/"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM-dd.txt"/>
<staticLogFileName value="false"/>
<layout type="log4net.Layout.PatternLayout">
<!--每条日志末尾的文字说明-->
<footer value="" />
<!--value类型:"记录时间:%date 线程ID:[%thread] 日志级别:%-5level 出错类:%logger property:[%property{NDC}] - 错误描述:%message%newline"-->
<conversionPattern value="%date ThreadID:[%thread] Log Level:%-5level Class:%logger Desp:%message%newline"/>
</layout>
</appender> <!--定义文件输出的名字以及文件的类型-->
<appender name="ErrorLogFileAppender" type="log4net.Appender.RollingFileAppender">
<!--定义文件存放的位置-->
<file type="log4net.Util.PatternString" value="..\log\%date{yyyyMMdd}\JOB_%property{jobid}_%date{yyyyMMdd}.log" />
<!--默认为true。当文件存在时,是否在原文件上追加内容,可是True/false,-->
<appendToFile value="true" />
<!--默认为true。为true时,RollingStyler的date值将无效。且为true时,需要在file里指定文件名,所有日志都会记录在这个文件里,false时间是相反的-->
<StaticLogFileName value="true"/>
<!--文件锁类型,RollingFileAppender本身并不是线程安全的,如果在程序中没有进行线程安全的限制,可以在这里进行配置,确保写入时的安全;文件锁定的模式有三个:
FileAppender.ExclusiveLock, FileAppender.MinimalLock and FileAppender.InterProcessLock,默认是第一个值,排他锁定,一次值能有一个进程访问文件,关闭后
另外一个进程才可以访问;第二个是最小锁定模式,允许多个进程可以同时写入一个文件;-->
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout">
<!--value类型:"记录时间:%date 线程ID:[%thread] 日志级别:%-5level 出错类:%logger property:[%property{NDC}] - 错误描述:%message%newline"-->
<conversionPattern value="%date{yyyy/MM/dd HH:mm:ss} %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="ERROR" />
</filter>
</appender>
<root>
<!--控制级别,由低到高: ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF-->
<!--如果定义级别为INFO,则INFO级别向下的级别,例如DEBUG日志将不会被记录-->
<!--如果没有定义LEVEL的值,则缺省为DEBUG-->
<level value="INFO" />
<appender-ref ref="ErrorLogFileAppender"/>
</root>
</log4net>
</configuration>

针对filter我也是感觉好奇,于是查找了一些资料,看到友友的总结,我还是拿来用一下,希望下次我在写log4net时间能够更快的寻找的到的啦,嘿嘿,下面就针对filter来总结一下,如下所示:

                <!--log4net里面的filter类常用的为:
、DenyAllFilter
拒绝所用的日志输出-->
<filter type="log4net.Filter.LevelMatchFilter">
<param name="LevelToMatch" value="DEBUG" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<!--上面的配置是如果日志的输出级别不符合DEBUG要求的话,则不输出任何日志。 、LevelMatchFilter
这个类里面有两个属性,一个是LevelToMatch这个属性,是要匹配输出日志的级别,例如:-->
<filter type="log4net.Filter.LevelMatchFilter">
<param name="LevelToMatch" value="DEBUG" />
</filter>
<!--这样的话,只有级别是DEBUG的日志才能输出。 另外这个类还有一个重要的属性就是AcceptOnMatch这个属性是设置如果这个条件匹配的话,是否接受输出打印,比如说:-->
<filter type="log4net.Filter.LevelMatchFilter">
<param name="LevelToMatch" value="DEBUG" />
</filter>
<filter type="log4net.Filter.StringMatchFilter">
<param name="StringToMatch" value="debug" />
</filter> <!--如果日志的级别为DEBVG的话,也就是说符合了第一个Filter的条件,日志就输出,则StringMatchFilter就不执行了。如果这样写的话,就会继续向下执行过滤:-->
<filter type="log4net.Filter.LevelMatchFilter">
<param name="LevelToMatch" value="DEBUG" />
<AcceptOnMatch value="false"></AcceptOnMatch>
</filter>
<filter type="log4net.Filter.StringMatchFilter">
<param name="StringToMatch" value="debug" />
</filter>
<!--如果这样写的话,即使第一个Filter符合了条件则第二个Filter也会继续执行。 、LevelRangeFilter
配置文件是这样的:-->
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="ERROR" />
</filter> <!--、LoggerMatchFilter
配置文件是这样的:-->
<filter type="log4net.Filter.LoggerMatchFilter">
<param name="LoggerToMatch" value="Client" />
</filter> <!--、StringMatchFilter
配置文件是这样的:-->
<filter type="log4net.Filter.StringMatchFilter">
<param name="StringToMatch" value="/blog/Client.Program" />
</filter>

4.日志的配置文件已经写好,下面我们就去Global.asax文件中进行配置,如下所示:

                 ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 

在Global.asax文件Application_Start方法下添加I上面的代码块即可。

5.我们在容易出错的类中添加我们的报错信息,例如简单的报错ex错误,如下:

                  try
{
}
catch (System.Exception ex)
{
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Error(ex.Message);
}

好啦,这样我们在出错时间就会创建log日志,然后告诉我们问题在哪里,嘿嘿,就总结到这里啦,加油亲们!

上一篇:log4j自动生成日志文件配置


下一篇:CreateCompatibleBitmap 需要注意的问题