One, log4net console, winform,webapplication use
1. First use NuGet to add log4net to the console project
log4j the specific meaning of each symbol:%d%5p%c{1}:%l-%m%n
Log4j.properties
# %m The message specified in the output code
#
#
#
#
#
#
# %l where the output log event occurs, including the class name, the thread that occurred, and the number of rows in the code.
log4j.appender.stdout.layout.conversionpattern=%d [%t]%-5p%c-%m%n
#日志文件 Daily
Log4j.appender.a1=org.apache.log4j.dailyrollingfileappender
Log4j.appender.a1.file=f:/mylog.txt
Log4j.appender.a1.layout=org.apache.log4j.patternlayout
#% time [% thread]%log level% full class name-% message% line break
log4j.appender.a1.layout.conversionpattern=%d [%t]%-5p%c-%m%n
2. Add the following in the console project's app. Config (as long as the add type, path, etc. of the settings log)
<log4net>
<appender name= "Rollinglogfileappender" type= "log4net. Appender.rollingfileappender ">
<param name= "File" value= "Log\log.txt"/>
<param name= "Appendtofile" value= "true"/>
<param name= "maxsizerollbackups" value= "/>"
<param name= "maximumFileSize" value= "2MB"/>
<param name= "Rollingstyle" value= "Size"/>
<param name= "Staticlogfilename" value= "true"/>
<layout type= "log4net. Layout.patternlayout ">
<param name= "Conversionpattern" value= "%-15p%d [%c]%m%n"/>
</layout>
</appender>
<root>
<level value= "All"/>
<appender-ref ref= "Rollinglogfileappender"/>
</root>
</log4net>
3. Add the following to the AssemblyInfo.cs in the properties of the console project
[Assembly:assemblyfileversion ("1.0.0.0")]
[Assembly:log4net. Config.xmlconfigurator (configfileextension = "config", Watch = True)]
4. Use in console project startup item projects
Static log4net. ILog Log = log4net. Logmanager.getlogger (typeof (program));
static void Main (string[] args)
{
Log.info ("111111111111111111111111");
Log.warn ("111111111111111111111111");
Log.error ("111111111111111111111111");
}
Log4net Console, winform,webapplication use