. NET Configuration log4net

Source: Internet
Author: User
Tags log4net

Using Log4net-1.2.0-beta8
Set in the project's AssemblyInfo.cs file

[Assembly:log4net. Config.domconfiguratorattribute (Watch=true)]
Add and edit the project configuration file (default is app.config), which reads as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<configSections>
<section name= "log4net" type= "log4net". Config.log4netconfigurationsectionhandler, log4net "/>
</configSections>
<log4net>
<appender name= "stdout" type= "log4net". Appender.consoleappender ">
<layout type= "log4net. Layout.patternlayout ">
<!--conversionpattern value= "[%d%l]%n%m%n"/-->
<param name= "Conversionpattern" value= "[%d%l]%m%n"/>
</layout>
</appender>
<appender name= "File" type= "log4net. Appender.fileappender ">
<param name= "File" value= "Log.txt"/>
<param name= "Appendtofile" value= "true"/>
<layout type= "log4net. Layout.patternlayout ">
<param name= "Conversionpattern" value= "[%d%l]%m%n"/>
</layout>
</appender>


<root>
<level value= "All"/>
<appender-ref ref= "stdout"/>
<appender-ref ref= "File"/>
</root>

<logger name= "*" >
<level value= "All"/>
<appender-ref ref= "stdout"/>
<appender-ref ref= "File"/>
</logger>
</log4net>
</configuration>

The following statement is used in the program code
...
Using Log4net;
Using Log4net. Config;
...
private static ILog log = Logmanager.getlogger (typeof (TestClass));
...
Log. Info ("This is a test!");

ok!.

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.