1. Download Log4net Development Package
2. Create a new Windows application and add Log4net.dll references to the project
3. Add the application configuration file to the project and name it Log4net.config, as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<!--Register A handler for the log4net section-->
<configSections>
<section name= "log4net" type= "log4net". Config.log4netconfigurationsectionhandler,log4net "/>
</configSections>
<!--This section contains the Log4net configuration settings-->
<log4net>
<!--Define some output appenders-->
<appender name= "Rollinglogfileappender" type= "log4net". Appender.rollingfileappender ">
<param name= "File" value= "Log\\log-iqslive.txt"/>
<param name= "Appendtofile" value= "true"/>
<param name= "Datepattern" value= "Yyyy-mm-dd"/>
<param name= "Rollingstyle" value= "Date"/>
<param name= "maxsizerollbackups" value= "/>"
<layout type= "log4net. Layout.patternlayout ">
<param name= "Conversionpattern" value= "%d{yyy-mm-dd HH:mm:ss} [%t] [%c]-[%-5p]%m%n"/>
</layout>
</appender>
<root>
<level value= "Debug"/>
<appender-ref ref= "Rollinglogfileappender"/>
</root>
</log4net>s
</configuration>
4. Add the following statement to the AssemblyInfo.cs file of the project:
[Assembly:log4net. Config.xmlconfigurator (Watch = true, ConfigFile = "Log4net.config")]
5. Add in the From1 class:
private static readonly log4net. ILog log = log4net. Logmanager.getlogger (System.Reflection.MethodBase.GetCurrentMethod (). DeclaringType);
6. Add a button and add the following code to the response event:
Log. Info ("button is clicked!");
7. Copy the Log4net.config file to the debug directory and run the program click button to see the log file under the Logs folder in the Debug directory