Use log4net-1.2.0-beta8
1> set it in the assemblyinfo. CS file of the project... If you forget this step, you will not be able to monitor the log file.
[Assembly: log4net. config. domconfiguratorattribute (watch = true)]
Or
[Assembly: log4net. config. xmlconfigurator (watch = true)]
2> Add and edit the project configuration file (App. config by default). The content is as follows:
Content 1:
<? 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. leleappender">
<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 = "stdout"/>
<Appender-ref = "file"/>
</Root>
<Logger name = "*">
<Level value = "all"/>
<Appender-ref = "stdout"/>
<Appender-ref = "file"/>
</Logger>
</Log4net>
</Configuration>
Or content 2 :]
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Configsections>
<Section name = "log4net" type = "log4net. config. log4netconfigurationsectionhandler, log4net"/>
</Configsections>
<Log4net DEBUG = "false">
<Appender name = "rollinglogfileappender" type = "log4net. appender. rollingfileappender">
<Param name = "file" value = "log/operationlog.txt"/>
<Appendtofile value = "true"/>
<Rollingstyle value = "date"/>
<Datepattern value = "yyyymmdd'.txt '"/>
<Layout type = "log4net. layout. patternlayout">
<Conversionpattern value = "% Date {yyyy-mm-dd hh: mm: SS }%%-5 level % message % newline"/>
</Layout>
</Appender>
<Root>
<Level value = "debug"/>
<Appender-ref = "rollinglogfileappender"/>
</Root>
</Log4net>
</Configuration>
(Content 2 can be directly copied for later use)
Use the following statement in the program code:
...
Using log4net;
Using log4net. config;
...
Private Static ilog log = logmanager. getlogger (typeof (testclass ));
...
Log. Info ("this is a test! ");