I have read a few tutorials on the Internet and have some minor problems. After some tests, I tried it and wrote the simplest one that can be used. I hope it will be useful to beginners!
First, add the following in APP. config:
Code
< Configsections >
< Section Name = "Log4net"
Type = "Log4net. config. log4netconfigurationsectionhandler, log4net-net-1.0" />
</ Configsections >
< Log4net >
< Root >
< Level Value = "Warn" />
< Appender-ref Ref = "Logfileappender" />
< Appender-ref Ref = "Leleappender" />
</ Root >
< Appender Name = "Logfileappender" Type = "Log4net. appender. fileappender" >
< File Value = "Log-file.txt" />
< Appendtofile Value = "True" />
< Layout Type = "Log4net. layout. patternlayout" >
< Header Value = "[Header] & amp; #13; & amp; #10 ;" />
< Footer Value = "[Footer] & amp; #13; & amp; #10 ;" />
< Conversionpattern Value = "% Date --- [% thread] %-5 level '% logger': % message % newline" />
</ Layout >
</ Appender >
< Appender Name = "Leleappender" Type = "Log4net. appender. leleappender" >
< Layout Type = "Log4net. layout. patternlayout" >
< Param Name = "Conversionpattern"
Value = "% D [% T] %-5 p (% C)-% m % N"
/>
</ Layout >
</ Appender >
</ Log4net >
Then add the following line in assemblyinfo. CS.
[Assembly: log4net. config. xmlconfigurator ()]
FinallyCode.
Code
Public Class Workerthreadexample
{
Private Static Readonly Log4net. ilog = Log4net. logmanager. getlogger ( " Test " );
Static Void Main ()
{
If (Log. isinfoenabled) log. Fatal ( " Application [consoleapp] Start " );
Log. Info ( " Error " );
Log. Fatal ( " Wadsadasd " );
}
}
For more information, see the document andArticleHowever, the config in this article seems to have some problems, mainly because the param settings are inconsistent with those in this document.
http://dragon.cnblogs.com/archive/2005/03/24/124254.aspx