I'm a Dummies. Today I want to talk about how to use log4net, of course. Under. net.
First, make sure that you have downloaded the log4net. dll file andProgramIn the bin folder, otherwise ......
1: In web. config<Configsections>... </configsections>Add:
<Section name = "log4net" type = "log4net. config. log4netconfigurationsectionhandler, log4net"/>
2:<Configuration>... </configuration>Add:
<Log4net DEBUG = "false">
<Appender name = "logfileappender" type = "log4net. appender. fileappender">
<Param name = "file" value = "D: \ applog.txt"/>
<Param name = "datepattern" value = "yyyy-mm-dd hh: mm"/>
<Param name = "appendtofile" value = "true"/>
<Layout type = "log4net. layout. patternlayout">
<Param name = "conversionpattern" value = "" % d % T % P % L % m % N "/>
</Layout>
</Appender>
<Appender name = "httptraceappender" type = "log4net. appender. aspnettraceappender">
<Layout type = "log4net. layout. patternlayout">
<Param name = "conversionpattern" value = "% d [% T] %-5 p % C [% x]-% m % N"/>
</Layout>
</Appender>
<Appender name = "eventlogappender" type = "log4net. appender. eventlogappender">
<Layout type = "log4net. layout. patternlayout">
<Param name = "conversionpattern" value = "% d [% T] %-5 p % C [% x]-% m % N"/>
</Layout>
</Appender>
<Appender name = "rollinglogfileappender" type = "log4net. appender. rollingfileappender">
<Param name = "file" value = "D: \ log.txt"/>
<Param name = "appendtofile" value = "true"/>
<Param name = "maxsizerollbackups" value = "10"/>
<Param name = "maximumfilesize" value = "5 MB"/>
<Param name = "rollingstyle" value = "size"/>
<Param name = "staticlogfilename" value = "true"/>
<Layout type = "log4net. layout. patternlayout">
<Param name = "conversionpattern" value = "% d [% T] %-5 p % C [% x]-% m % N"/>
</Layout>
</Appender>
<Root>
<Level value = "debug"/>
<Appender-ref = "logfileappender"/>
</Root>
</Log4net>
3: Finally, define a log object in the Aspx. CS or CS class to record the log:
Private Static log4net. ilog log = log4net. logmanager. getlogger ("debug ");
4: call:
InCodeBlock, add this line, OK!
Log. debug ("XX operation recorded");
5:Finally, I will explain "% d % T % P % L % m % N" in Web. config:
% D:The date or time of the log output time point,You can specify a format later, for example, % d {yyyy-mm-dd hh: mm: SS}. The output is similar to: 17:49:27, which is suitable for inserting sqlserver;
% T:The thread name that generates the log event;
% P: log_level of the log, such as debug, warn, Or info;
% C: the output category, usually the full name of the class, such as "iNotes. Default ";
% M: log content;
% L: the location where the output log event occurs, including the category name, the thread that occurs, and the number of lines in the code.
% N output a carriage return line break, wiThe ndows platform is "\ r \ n" and the UNIX platform is "\ n"
If you still don't know much about it, use the format % d % T % P % L % m % N. I set it so clearly.
Dummies: Blue breeze QQ: 3053166