Just beginning to contact ASP.net, about how to log records less, so a simple record of log4net configuration and use, in case you forget later.
first introduced Log4net.dll, about the file of their own Baidu download.
Then configure the configuration and add the Web.config to the configuration node
<configSections> <section name= log4net "type=" log4net. Config.log4netconfigurationsectionhandler, log4net "/> </configSections> <log4net> <appender name= "Rollingfile" type= "log4net. Appender.rollingfileappender,log4net "> <param name=" "File" value= "log/"/> "<param" name= "AppendToFile" Value= "true"/> <param name= "Rollingstyle" value= "Date"/> "<param" name= "Datepattern" value= "Yyyy-MM-dd". Log ""/> <param name= "Staticlogfilename" value= "false"/> <layout "type=". Layout.patternlayout "> <param name=" Conversionpattern "value="%n%r%p[%d%c]%m%n "/> </layout> </app ender> <root> <level value= "All"/> <appender-ref ref= "Rollingfile"/> </root> <logge R name= "Weblogger" > <level value= "All"/> <appender-ref ref= "Rollingfile"/> </logger> </log4n Et>
then add in the Application_Start method of Global.asax
Log4net. Config.XmlConfigurator.Configure ();
Finally write a log output class for easy invocation
public class MyLog
{
private static readonly log4net. ILog log = log4net. Logmanager.getlogger ("Weblogger");
Public MyLog ()
{
}
private static void Setconfig ()
{
object o = Configurationmanager.getsection (" Log4net ");
Log4net. Config.XmlConfigurator.Configure (o as System.Xml.XmlElement);
}
public static void Loginfo (String message)
{
if (!log). isinfoenabled)
setconfig ();
Log. Info (message);
}
public static void Loginfo (String message, Exception Ex)
{
if (!log). isinfoenabled)
setconfig ();
Log. Info (message, ex);
}
public static void ErrorInfo (String message)
{
if (!log). isinfoenabled)
setconfig ();
Log. Error (message);
}
public static void Debuginfo (String message)
{
if (!log). isinfoenabled)
setconfig ();
Log. Debug (message);
}
Then you can use the log output in individual code!
about log4net configuration for the time being, I haven't looked at it carefully, so I'll continue to study it when we are free.