Log4net log segmentation, split by size

Source: Internet
Author: User
Tags log4net

Recently wrote a socket communication of the watch online service side, in the log, recording the Log4net log segmentation

1. Introduction of Log4net.dll

2.web.config Add configsection Handler mappings:

<configuration>    <configSections>      <section name="log4net" type= " log4net. Config.log4netconfigurationsectionhandler,log4net" />    </configsections></ Configuration>

3. Create the Log4net.config file, which is generated by date under the Logs folder

<?XML version= "1.0" encoding= "Utf-8"?><log4net>  <!--OFF, FATAL, ERROR, WARN, INFO, DEBUG, all -  <!--Set Root Logger level-to-ERROR and its appenders -  <Root>    < Levelvalue= "All"/>    <Appender-refref= "Sysappender"/>  </Root>  <!--Print only messages of level DEBUG or above in the packages -  <Loggername= "Weblogger">    < Levelvalue= "DEBUG"/>  </Logger>    <Appendername= "Sysappender"type= "log4net." Appender.rollingfileappender,log4net " >    <paramname= "File"value= "logs/" />    <paramname= "Appendtofile"value= "true" />    <paramname= "Rollingstyle"value= "Date" />    <paramname= "Datepattern"value= "&quot; Logs_&quot;yyyymmdd&quot;. txt&quot; " />    <paramname= "Staticlogfilename"value= "false" />    <Layouttype= "log4net." Layout.patternlayout,log4net ">      <paramname= "Conversionpattern"value= "%d [%t]%-5p%c-%m%n" />      <paramname= "Header"value= "& #13;& #10;----------------------header--------------------------& #13;& #10;" />      <paramname= "Footer"value= "& #13;& #10;----------------------footer--------------------------& #13;& #10;" />    </Layout>  </Appender>  <Appendername= "ConsoleApp"type= "log4net." Appender.consoleappender,log4net ">    <Layouttype= "log4net." Layout.patternlayout,log4net ">      <paramname= "Conversionpattern"value= "%d [%t]%-5p%c-%m%n" />    </Layout>  </Appender></log4net>

4. Partition-by-size mapping file

<?XML version= "1.0" encoding= "Utf-8"?><log4net>  <!--OFF, FATAL, ERROR, WARN, INFO, DEBUG, all -  <!--Set Root Logger level-to-ERROR and its appenders -  <Root>    < Levelvalue= "All"/>    <Appender-refref= "Sysappender"/>  </Root>  <!--Print only messages of level DEBUG or above in the packages -  <Loggername= "Weblogger">    < Levelvalue= "DEBUG"/>  </Logger>    <Appendername= "Sysappender"type= "log4net." Appender.rollingfileappender ">    <paramname= "File"value= "Logs\logs.txt"/>    <paramname= "Appendtofile"value= "true"/>    <paramname= "Maxsizerollbackups"value= " a"/> <!--cutting the maximum number of files -    <paramname= "maximumFileSize"value= "500KB"/> <!--the size of each file -    <paramname= "Rollingstyle"value= "Size"/>    <paramname= "Staticlogfilename"value= "true"/>    <Layouttype= "log4net." Layout.patternlayout ">      <paramname= "Conversionpattern"value= "%d [%t]%-5p%c [%x]-%m%n"/>    </Layout>  </Appender></log4net>

My notes:

The configuration file is the declaration of the corresponding class with reflection and name, Rollingfileappender the Sysappender object, and the following are the individual parameters of this class. This class is usually designed like this.

Log4net log segmentation, split by size

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.