Log4net Study Notes

Source: Internet
Author: User
Tags log4net

In the most basic usage:

Refer:http://www.cnblogs.com/aehyok/archive/2013/05/07/3066010.html

<configuration>  <configSections>    <section name="log4net" type= " log4net. Config.log4netconfigurationsectionhandler, log4net" />  </configsections></ Configuration>
<configuration> <log4net debug="true"> <!--all| debug|info| warn| error| fatal| off--> <root> <level value="Debug"/> <appender-ref ref="Logfileappender"/> <appender-ref ref="Smtpappender"/> </root> <logger name="loggering"> <!--<level value="Debug"/> <appender-ref ref="Logfileappender"/>--> </logger> <appender name="Logfileappender"Type="log4net. Appender.fileappender"> <param name="File"Value="D:\Google drive\learn\logfornet\logfornet\log\log.txt"/> <param name="Appendtofile"Value="true"/> <layout type="log4net. Layout.patternlayout"> <!--Output Control--<!--<param Name="Conversionpattern"Value="%d [%t]%-5p%c [%x]-%m%n"/>--> <param name="Conversionpattern"Value="%d%-5p:%m%n"/> </layout> </appender> <appender name="Smtpappender"Type="log4net. Appender.smtpappender"> <authentication value="Basic"/> <to value="[email protected]"/> < fromValue="[email protected]"/> <username value="[email protected]"/> <password value="I ( ...)"/> <subject value="Program exception logging mail sending"/> <smtphost value="mail.stooges.com.my"/> <enablessl value="false"/> <port value="587"/> <buffersize value=" +"/> <lossy value="true"/> <evaluator type="log4net. Core.levelevaluator"> <threshold value="Error"/> <!--intercept error-</evaluator> <layout type="log4net. Layout.patternlayout"> <conversionpattern value="%newline%date [%thread]%-5level%logger [%PROPERTY{NDC}]-%message%newline%newline%newline"/> </layout> </appender> </log4net></configuration>
void Application_Start (object  sender, EventArgs e) {    log4net. Config.XmlConfigurator.Configure ();     // Code that runs on application startup     Arearegistration.registerallareas ();    Globalconfiguration.configure (webapiconfig.register);    Routeconfig.registerroutes (routetable.routes);            }

 Public classhomecontroller:controller{Private Static ReadOnlyILog log = Logmanager.getlogger ("loggering"); //Get:home     PublicActionResult Index () {Try{log. Info ("Log Logging Information"); Log. Debug ("Debug Information"); //log.            Error ("error message"); //log.            Warn ("Warn information"); //Exception ex = new Exception ("Abnormal information for testing"); //log. Fatal ("Fatal information", ex);         }        Catch(Exception ex) {Throw; }                 returnView (); }       }

Log4net Study Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.