A preface
The log4net configuration found on the Internet is mostly for Web application projects and WinForm projects, too little or no description of Web site projects. The difference between Web application project and Web site project please refer to http://www.cnblogs.com/ceachy/articles/2149075.html
This article describes the Log4net configuration under the Web site project.
Two Solutions
1. Add the Log4net.config configuration file to the Web site project, and the configuration file reads as follows
<?xml version= "1.0" encoding= "Utf-8"?> <configuration> <configSections> <!--type comma followed by log4n ET's DLL name--> <section name= "log4net" type= "log4net". Config.log4netconfigurationsectionhandler,log4net "/> </configSections> <system.web> <compi
Lation debug= "false" targetframework= "4.0"/> </system.web> <log4net> <!--definition output to file--> <appender name= "Logfileappender" type= "log4net". Appender.fileappender "> <!--define file location--> <file value=" App_data/lqz.log "/> <appendtofile Value= "true"/> <rollingstyle value= "Date"/> <datepattern value= "Yyyymmdd-hh:mm:ss" ; Layout type= "log4net. Layout.patternlayout "> <!--text description at the end of each log--> <footer value=" by saibo3s "/> <!--output format --> <!--sample: 2008-03-26 13:42:32,111 [ten] INFO log4netdemo.mainclass [(null)]-info--> <conver Sionpattern value= "%date thread Id:[%thread] level:%-5level%n%c [%p]%n-Error description:%m%n"/> </layout> </appender> <!--define output to the console command line--> <appender name= "Consoleappender type=" log4net. Appender.consoleappender "> <layout type=" log4net.
Layout.patternlayout "> <param name =" Conversionpattern "value="%d [%t]%-5level%c [%p]-%m%n "/> <!--<conversionpattern value= "%d [%t]%-5level%c [%p]-%m%n"/>--> </layout> </APPENDER&G
T The <!--defines the output media for the log, and the following defines the log output in four different ways. You can also export by one type or other type below. --> <root> <level value= "DEBUG"/> <!--file Form log--> <appender-ref ref= "LogFile Appender "/> <!--console controls the display log, disabling--> <!--<appender-ref ref=" Consoleappender "in the Web project/>--> & Lt;/root> <!--Specifies the log level--> <!--<logger name = "Frstrightfactory" additivity = False for a child log object (the class name that requires logging) "> <level value =" DEBUG "></level> </loGger>--> </log4net> </configuration>
2. Modify Global.asax
[Assembly:log4net. Config.xmlconfigurator (watch=true)]
void Application_Start (Object Sender,eventargs e)
{
//Add content Start
string s = Server.MapPath ("Log4net.config");
System.IO.FileInfo info = new System.IO.FileInfo (s);
Log4net. Config.XmlConfigurator.Configure (info);
Add content End
}
3. Use Log4net.
To define a static member variable log in a class
private static readonly ILog log = Logmanager.getlogger (typeof (My_class). Name);
Use the log method in the class's method, as follows
if (log. isdebugenabled)
{
Log. Debug ("Sfsag");
}