Log4net is a log assembly developed by Apache. Like its sister log4j, it is an open source project. You can apply in your system in your plug-in. Use only how to apply in the Web Forms project. Be the main log output component .
1. Download the Log4Net master is: http://logging.apache.org/log4net/
2. Add log4net.dll and introduce it into your project References.
3. You need to modify your global.asa.cs. Configure the Application object to load the log4net configuration when the Application object is started. This step is not missing .protected void Application_Start (Object Sender, Eventargs E) {log4net.config.Domconfigurator.configure () }
4. You can see that the above code is no parameters. It can be seen that the default configuration is loaded. This configuration must be set in Web.config. Add the following section: configsections> 4. This config section declares another config section named log4Net. The latter must be in Web.config's root node Configuration: The following is one Sample: layout> appender> layout> appende R> layout> appender> layout> appender> root> log4net> 5. The above defines multiple appenders. Each appender is an output Medium .6. The root node specifies the selected appender. This example is selected. (Text file output). Define the output format in the appender definition. The location of the target text file is located. (The starting position is the root directory of the application (Web.config) .7. Configure log4net to the current location. You can use it directly in our application. 8. Here, the application method: To output the log, you must first get the Logger with one alias. . Using the following command (C #): log4net.logManager.getlogger (this.gettype ()); (this can be used directly to get the current class name) After calling Logger.info (S) TRING MESSAGE); Logger.Error (String Message); Logger.debug (String Message); You can output a log. After debugging, you can find the XXXXXApplication.log.txt text file that has been automatically created in the application root directory. And whether it is correct The log.
Log4net is a very perfect log component. It has powerful configurability. Helps improve development efficiency.