Simple use of Log4net and simple use of Log4net

Source: Internet
Author: User

Simple use of Log4net and simple use of Log4net

First, add a reference to log4net. You can download it using VS Nuget.

1. Configure the Web. config file and configure the section in configSections under the configuration node.

  <configSections>    <!-- Add log4net config section-->    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,     log4net" />  </configSections>

 

2. Add a log4net node under the configuration Node

<Log4net debug = "true"> <appender name = "RollingLogFileAppender" type = "log4net. appender. rollingFileAppender "> <file value =" logs \ log.txt "/> // file storage location <appendToFile value =" true "/> <rollingStyle value =" Size "/> <maxSizeRollBackups value = "10"/> <maximumFileSize value = "10 MB"/> <staticLogFileName value = "true"/> <layout type = "log4net. layout. patternLayout "> <conversionPattern value =" %-5 p % d % 5rms %-22.22c {1 }%- 18.18 M-% m % n "/> </layout> </ appender> <root> <level value = "DEBUG"/> <appender-ref = "RollingLogFileAppender"/> </root> </log4net>

When writing logs in the background:

Public ActionResult Index () {ILog log = log4net. logManager. getLogger ("RollingLogFileAppender"); log. error ("Haha yes"); return View ();}

So far

 

Related Article

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.