1. NuGet Download log4net
2. Add configuration information in app. Config
< Sectionname= "Log4net"type= "log4net." Config.log4netconfigurationsectionhandler, log4net " /> <log4net> <!--OFF, FATAL, ERROR, WARN, INFO, DEBUG, all - <!--Set Root Logger level-to-ERROR and its appenders - <Root> < Levelvalue= "All" /> <Appender-refref= "Sysappender" /> </Root> <!--Print only messages of level DEBUG or above in the packages - <Loggername= "Testlogger"> < Levelvalue= "All" /> </Logger> <Appendername= "Sysappender"type= "log4net." Appender.rollingfileappender,log4net "> <!--Log Directory - <paramname= "File"value= "log/" /> <paramname= "Appendtofile"value= "true" /> <paramname= "Rollingstyle"value= "Date" /> <!--Log Naming - <paramname= "Datepattern"value= "" Logs_"yyyymmdd". txt" " /> <paramname= "Staticlogfilename"value= "false" /> <Layouttype= "log4net." Layout.patternlayout,log4net "> <paramname= "Conversionpattern"value= "%d [%t]%-5p%c-%m%n" /> </Layout> </Appender> <Appendername= "ConsoleApp"type= "log4net." Appender.consoleappender,log4net "> <Layouttype= "log4net." Layout.patternlayout,log4net "> <paramname= "Conversionpattern"value= "%d [%t]%-5p%c-%m%n" /> </Layout> </Appender> </log4net>
3. Add the following code in AssemblyInfo.cs or above the log class namespace
// log4net reading the configuration from the configuration file " Config " true)]
(Specify configuration file method)
// Add log4net information " Log.config " true)]
4. Using log4net
Private StaticILog log = Logmanager.getlogger ("Testlogger"); Static voidMain (string[] args) {log. Debug ("Debug Log"); Log. Info ("Info Log"); Log. Warn ("warn log"); Log. Error ("error Log"); }
Use of log4net