Http://www.csharpwin.com/csharpspace/678.shtml
1. Download log4net (Google log4net)
2.unzip log4net
3. Run VS, create a new C # Windows application.
4. Add Reference log4net
5. Create a new application configuration file, App. config (details attached)
6. Open Form1.cs, 
adds a row [namespace] on assembly:log4net. Config.domconfigurator (watch=true)] 
(or edit the Assembly.cs file, add the following: Span class= "Apple-converted-space" > 
[Assembly:log4net. Config.domconfigurator (configfileextension= "config", Watch=true)])
Adds a static variable to the class Form1  
private static readonly log4net. ILog log = log4net. Logmanager.getlogger (System.Reflection.MethodBase.GetCurrentMethod (). DeclaringType);  
7. Add a button. Add a row of logs to the button handler. Warn ("Hello! ");  
8. Run the program. Click the button.  
OK, open bin\debug\log-file.txt and you can see "Hello".  
attached. app.config
Actual use:
<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<configSections>
<section name= "log4net" type= "System.Configuration.IgnoreSectionHandler"/>
</configSections>
<appSettings>
</appSettings>
<log4net>
<appender name= "Logfileappender" type= "log4net. Appender.rollingfileappender ">
<file value= "dmhjpgrklog. Log"/> file name
<appendtofile value= "true"/>
<rollingstyle value= "Size"/>
<maxsizerollbackups value= "3"/>
<maximumfilesize value= "30MB"/>
<staticlogfilename value= "true"/>
<datepattern value= "Yyyymmdd-hh:mm:ss"/>
<layout type= "log4net. Layout.patternlayout ">
<conversionpattern value= "%date[tid:%-5thread][%level][%logger"%message%newline "/>
</layout>
</appender>
<appender name= "Consoleappender" type= "log4net. Appender.consoleappender ">
<layout type= "log4net. Layout.patternlayout ">
<conversionpattern value= "%date [%thread]%-5level%logger [%PROPERTY{NDC}]-%message%newline"/>
</layout>
</appender>
<root>
<level value= "All"/>
<appender-ref ref= "Logfileappender"/>
<appender-ref ref= "Consoleappender"/>
</root>
</log4net>
</configuration>
AssemblyInfo.cs
Add Log4net to this project
[Assembly:log4net. Config.xmlconfigurator (configfile = "RK. config", Watch = True)]
Call------------------------------------------------------------
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Text;
Using System.Windows.Forms;
Using Log4net;
[Assembly:log4net. Config.domconfigurator (Watch = True)]
Namespace WindowsApplication1
{
public partial class Form1:form&NBSP;
{&NBSP;
Public Form1 () &NBSP;
{&NBSP;
InitializeComponent (); &NBSP;
}&NBSP;
private static readonly log4net. ILog log = log4net. Logmanager.getlogger (System.Reflection.MethodBase.GetCurrentMethod (). DeclaringType); &NBSP;
private void Button1_Click (object sender, EventArgs e) &NBSP;
{&NBSP;
Log. Warn ("Hello! "); &NBSP;
}&NBSP;
}