1) The first step is also the most important step: Download a log4net. dll file, of course, you can also download the source file on the official website, and compile and generate such a file yourself
2) the configuration file is created. Create a log4net. xml file:
The configuration is as follows: the specific configuration depends on the situation. Only one framework is provided here:
<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <configsections> <section name = "log4net" type = "log4net. config. log4netconfigurationsectionhandler, log4net "/> </configsections> <log4net> <root> <level value =" error "/> </root> <logger name =" dataserverlog "> <level value =" error "> </level> <appender-ref =" dataserverappender "/> </logger> <appender name =" dataserverappender "type =" log4net. appender. fileappender "> <Param name =" file "type =" log4net. util. patternstring "value =" % log \ % Date {yyymmdd }. log "/> <Param name =" appendtofile "value =" true "/> <Param name =" rollingstyle "value =" date "/> <datepattern value =" yyyymmdd /" dataserver _ "yyyymmdd ". log ""/> <Param name = "maxsizerollbackups" value = "10"/> <Param name = "maximumfilesize" value = "5 MB"/> <Param name = "staticlogfilename "value =" false "/> <layout type =" log4net. layout. patternlayout "> <Param name =" conversionpattern "value =" record time: % date thread ID: [% thread] Log Level: %-5 level error class: % logger property: [% property {NDC}]-error Description: % message % newline "/> </layout> </appender> </log4net> </configuration>
3) add [Assembly: log4net. config. xmlconfigurator (configfile = "log4net. xml", watch = true) at the end of the assemblyinfo. CS file]
4) Replace the default value of copying data from the log4net. xml attribute to the output directory with: Always copy
Now, you can use log4net to generate a log file.