Log4net Configuring and getting Ilog instances

Source: Internet
Author: User
Tags log4net

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&quot;. htm&quot;"/> <layout type="log4net. Layout.patternlayout"> <param name="Conversionpattern"Value="&lt;hr color=red&gt;%n Exception time:%d [%t] &lt;br&gt;%n exception level:%-5p &lt;br&gt;%n Exception class:%c [%x] &lt ; br&gt;%n%m &lt;br&gt;%n &lt;hr size=1&gt;"/> </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&quot;. htm&quot;"/> <layout type="log4net. Layout.patternlayout"> <param name="Conversionpattern"Value="&lt;hr color=blue&gt;%n Log time:%d [%t] &lt;br&gt;%n log level:%-5p &lt;br&gt;%n Log class:%c [%x] & Lt;br&gt;%n%m &lt;br&gt;%n &lt;hr size=1&gt;"/> </layout> </appender></log4net>

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.