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= "" Logs_"yyyymmdd". txt" " /> <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