Log4net Log
Summary:
Log4net is a tool that helps programmers output log information to various targets (console, file, database, etc.). The log is the black box of the program. You can use the log to view the running process of the system and discover system problems. The function of logs: record the steps, successes and failures of the running process, record key data, and then analyze system problems. Because for websites, exception information cannot be displayed to users, and exception information can only be recorded in the log. When there is a problem with the website, the developer knows the problem by looking at the logs.
##1. How to configure the Log4net environment9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
1. Add "Application Configuration File" (App.config);9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
2. Add configuration in App.config or Web.config:9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
<log4net> <!-- Define some output appenders --> <appendernameappendername="RollingLogFileAppender"type="log4net.Appender.RollingFileAppender"> <file value="test.txt"/> <appendToFilevalueappendToFilevalue="true"/> <maxSizeRollBackupsvaluemaxSizeRollBackupsvalue="10"/> <maximumFileSizevaluemaximumFileSizevalue="1024KB"/> <rollingStylevaluerollingStylevalue="Size"/> <staticLogFileNamevaluestaticLogFileNamevalue="true"/> <layouttypelayouttype="log4net.Layout.PatternLayout"> <conversionPattern value="%date[%thread] %-5level %logger - %message%newline"/> </layout> </appender> <root> <level value="DEBUG"/> <appender-refrefappender-refref="RollingLogFileAppender"/> </root> </log4net>3. Add Log4net.dll reference;
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
4. The attribute "Copy to output directory" of log4net.config is set to "Always copy";9TBHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
5. Initialization:9TBHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
2. Log4NetDemo9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
9TBHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
<html> <head></head> <body> <pre code_snippet_id="2146508" snippet_file_name="blog_20170123_2_6827063" name="code" class="csharp"> namespace Log4NetDemo { class Program { static void Main(string[] args) { //使用log4net记录日志。 log4net.Config.XmlConfigurator.Configure(); ILog logWriter =log4net.LogManager.GetLogger("Test"); logWriter.Info("消息"); logWriter.Warn("警告"); logWriter.Error("异常"); logWriter.Fatal("错误"); } } }
<strong><span style="font-family:SimHei; font-size:18px"> <img src="//m.sbmmt.com/20170123115415135?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvV0tYMTgzMzA2OTg1MzQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /> 更多内容,推荐阅读: </span></strong>