Configure and use log4net

Source: Internet
Author: User

You don't need to reference log4net. dll first.

 

The configuration and usage are as follows:

 

Configure in Web. config

 

<Configuration>

<Configsections>
<Section name = "log4net" type = "log4net. config. log4netconfigurationsectionhandler, log4net"/>

</Configsections>

 

<Log4net DEBUG = "false">
<Appender name = "rollinglogfileappender" type = "log4net. appender. rollingfileappender">
<File value = "D:/log/logfile"/>
<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>

</Configuration>

 

The next step is to use

 

Private Static ilog log = logmanager. getlogger (typeof (mylog ));

 

Mylog is the current class name.

 

 

Then, you can log. Error (MSG), log. debug (MSG), and log. Warn (MSG) as needed.

 

 

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.