Name |
Describe |
File |
The file path, if Rollingstyle is composite or date, is set here as a directory, the file name is set in Datepattern, and the others have a file name. Supported virtual directories have been extended |
Rollingstyle |
How to create a new file, optionally a size(by file size),date(by date),Once(one file per launch),Composite(by date and file size), Default is Composite |
Datepattern |
When Rollingstyle is composite or date, the file name format is set here |
Staticlogfilename |
True/false, which is true by default. When True, the date value of Rollingstyler is not valid. And true, you need to specify the file name in file, and all logs will be recorded in this document. |
maximumFileSize |
When Rollingstyle is composite or size, the maximum file size is set here (can be KB,MB,GB as the default byte) |
Countdirection |
The default value is-1. When a file exceeds the size of maximumfilesize, if you want to create a new file to store the log, the file is renamed according to the value of countdirection. When the value is greater than-1, the file name specified in file is incremented by. 0,.1,.2. When equal to or less than-1, creation relies on the maxsizerollbackups parameter value to create the number of backup logs. |
Maxsizerollbackups |
The number of backup logs, which defaults to 0. Valid when the countdirection is negative. |
Threshold |
The starting log level, which is the predefined log level discussed in the following article. Logs below this level are not logged. |
Appendtofile |
True/false, which is true by default. Whether the content is appended to the original file when the file exists. |
Reference Address: http://blog.csdn.net/work888study/article/details/9113027
Configuration:
1. under Startup Project Properties---AssemblyInfo.cs added,
[Assembly:log4net. Config.xmlconfigurator (configfile = "Log4net.config", configfileextension = "config", Watch = True)]
2. Initialize under Startup Project ,
Log4helper.logerror = log4net. Logmanager.getlogger ("Logerror");
Log4helper.loginfo = log4net. Logmanager.getlogger ("Loginfo");
3. Also add Log4net.config under Startup Project and set its properties " Copy to output directory-copy if newer "
<log4net> <logger name="Logerror"> <level value=" All"/> <appender-ref ref="Errorappender"/> </logger> <logger name="Loginfo"> <level value=" All"/> <appender-ref ref="Infoappender"/> </logger> <appender name="Errorappender"Type="log4net. Appender.rollingfileappender"> <param name="File"Value="log\\logerror\\"/> <param name="Appendtofile"Value="false"/> <param name="Rollingstyle"Value="Composite"/> <param name="maximumFileSize"Value="100MB"/> <param name="maxsizerollbackups"Value=" +"/> <param name="Staticlogfilename"Value="false"/> <param name="Datepattern"Value="Yyyy\\yyyymm\\yyyymmdd". htm""/> <layout type="log4net. Layout.patternlayout"> <param name="Conversionpattern"Value="<hr color=red>%n Exception time:%d [%t] <br>%n exception level:%-5p <br>%n Exception class:%c [%x] < ; br>%n%m <br>%n <hr size=1>"/> </layout> </appender> <appender name="Infoappender"Type="log4net. Appender.rollingfileappender"> <param name="File"Value="log\\loginfo\\"/> <param name="Appendtofile"Value="false"/> <param name="Rollingstyle"Value="Composite"/> <param name="maximumFileSize"Value="100MB"/> <param name="maxsizerollbackups"Value=" +"/> <param name="Staticlogfilename"Value="false"/> <param name="Datepattern"Value="Yyyy\\yyyymm\\yyyymmdd". htm""/> <layout type="log4net. Layout.patternlayout"> <param name="Conversionpattern"Value="<hr color=blue>%n Log time:%d [%t] <br>%n log level:%-5p <br>%n Log class:%c [%x] & Lt;br>%n%m <br>%n <hr size=1>"/> </layout> </appender></log4net>