Simple use of Log4net and simple use of Log4net
First, add a reference to log4net. You can download it using VS Nuget.
1. Configure the Web. config file and configure the section in configSections under the configuration node.
<configSections> <!-- Add log4net config section--> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections>
2. Add a log4net node under the configuration Node
<Log4net debug = "true"> <appender name = "RollingLogFileAppender" type = "log4net. appender. rollingFileAppender "> <file value =" logs \ log.txt "/> // file storage location <appendToFile value =" true "/> <rollingStyle value =" Size "/> <maxSizeRollBackups value = "10"/> <maximumFileSize value = "10 MB"/> <staticLogFileName value = "true"/> <layout type = "log4net. layout. patternLayout "> <conversionPattern value =" %-5 p % d % 5rms %-22.22c {1 }%- 18.18 M-% m % n "/> </layout> </ appender> <root> <level value = "DEBUG"/> <appender-ref = "RollingLogFileAppender"/> </root> </log4net>
When writing logs in the background:
Public ActionResult Index () {ILog log = log4net. logManager. getLogger ("RollingLogFileAppender"); log. error ("Haha yes"); return View ();}
So far