Log4net Configuration Turn

Source: Internet
Author: User

Http://www.cnblogs.com/qingyi/archive/2010/01/14/1647915.html

Always forget something with some things, remember it here first.

<!--log4net related instructions
I. Configuration
1. Associate profiles are configured in AssemblyInfo.cs
Add [Assembly:log4net. Config.domconfigurator (configfile= "Log4net.config", configfileextension= "ext", Watch=true/false)]
Description
configfile-== refers to the path of the log4net configuration file, relative to the root path of the application
ext== If we use different file extensions for the compiled program's assembly, we need to define this property, by default, the assembly's configuration file extension is "config".
Watch (Boolean property): The Log4net framework uses this property to determine whether changes to the file need to be monitored at run time. If this property is true,
Then FileSystemWatcher will be used to monitor file changes, rename, delete and other events.
Note: The ConfigFile and Configfileextension properties cannot be used at the same time, ConfigFile indicates the name of the configuration file, for example, configfile= "Config.txt" configfileextension = "TXT", then the configuration file should be "Test.exe.txt";
Log4net.config File Description-
<log4net> <!--framework The unique identifier to find in the configuration file is <log4net> label--
<root> <!--root log definition--
<level value= "WARN"/> <!--
The definition level defaults to debug (values from high to low can be: off--deny all FATAL ERROR WARN INFO DEBUG all--allow all)
When you invoke the appropriate log method, the framework checks the corresponding Boolean property to determine whether the method can be executed.
-
<appender-ref ref= "Logfileappender"/> <!--define output media--
<appender-ref ref= "Consoleappender"/>
</root>
<logger name= "testapp.logging" additivity= "false" >
<!--
Pre-defined settings for a specific log object, and then by calling Logmanager.getlogger ("testapp.logging")
Additivity whether to inherit root
-
<level value= "DEBUG"/>
</logger>
<appender name= "Logfileappender" type= "log4net. Appender.fileappender "> <!--type: Defines the output media as a text file--
<param name= "File" value= "Log-file.txt"/> <!--file path relative to root path--
<param name= "Appendtofile" value= "true"/> <!--append to file or overwrite file--
<layout type= "log4net. Layout.patternlayout "> <!--display the last formatted output information to the user--
<param name= "Header" Value= "[Header]"/> <!--head-to-
<param name= "Footer" value= "[Footer]"/> <!--footnotes--
<param name= "Conversionpattern" value= "%d [%t]%-5p%c [%x]-%m%n"/>
<!--
%M (message): Output log message, such as Ilog.debug (...) A message for the output
%n (New line): NewLine
%d (datetime): Outputs the moment at which the current statement runs
%r (Run time): The number of milliseconds that the output program consumes from running to executing to the current statement
%T (thread ID): The thread ID where the current statement is located
%p: The current priority level of the log, which is debug, INFO, WARN ... such as
%c (Class): The name of the current log object, for example:
%l: The line number where the output statement is located
%F: The file name where the output statement resides
%-Number: Indicates the minimum length of the item and, if not enough, fills it with a space
-
</layout>
<filter type= "log4net. Filter.levelrangefilter "> <!--filters applied to appender objects--
<param name= "Levelmin" value= "DEBUG"/>
<param name= "Levelmax" value= "WARN"/>
</filter>
</appender>
<appender name= "Consoleappender" type= "log4net. Appender.consoleappender ">
<layout type= "log4net. Layout.patternlayout ">
<param name= "Conversionpattern" value= "%d [%t]%-5p%c [%x]-%m%n"/>
</layout>
</appender>
</log4net>

<!--2. Configuring in Web. config
<configSections>
<section name= "log4net" type= "log4net. DLL name for config.log4netconfigurationsectionhandler,log4net "/>
</configSections>

Create or get a log object
Log4net.ilog log = Log4net.LogManager.GetLogger ("MyLogger");
Log. Info ("message");
-

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.