I'm a Dummies. Today I want to talk about how to use log4net, of course. Under. net.
First, make sure that you have downloaded the log4net. dll file andProgramIn the bin folder, otherwise ......
1: In web. configAdd:
2:Add:
3: Finally, define a log object in the Aspx. CS or CS class to record the log:
Private Static log4net. ilog log = log4net. logmanager.
Hello, log4net----- Use log4net in C #
1. Download log4net (Google log4net)2. Unzip log4net3. Run vs to create a new C # windows application.4. Add reference log4net5. Create an application configuration file app. config (the specific content is attached to it)6. Open form1.cs,Add a line in namespace [Assembly: log4net. config. domconfigurator (watch = true)]Add a static variable to the form1 classPrivate Static readonly log4net. ilog log = log4net. logmanag
Reference: http://www.cnblogs.com/dragon/archive/2005/03/24/124254.html
Today, I have been away from my company for more than a week. I used log4net to provide the log function to improve my own systems.
1. Add reference
Add a log4net (download: http://logging.apache.org/log4net/download.html) reference and reference the DLL or source code project.
2. modify or add app. config
By default, an app. config file is added to the project.
After the program is compiled, A
3. Edit the app. config file
("Logerror"); if(ex! =NULL) {task.run ()= = Log. Error (msg, ex));//Asynchronous } Else{task.run ()= = Log. Error (msg));//Asynchronous } } #endregion }}View the background code you will find that the error example has two methods, two ways to pass the parameters, our package above is also based on our business needs, to expand the packageMethod Analytic focus:: the Logmanager class, which is used to
article: http://blog.csdn.net/lyjcn/archive/2009/08/11/4432833.aspx can also view the official documentation.
The appender name defined above is file, which must also be used in the Code. Otherwise, an error occurs that the object cannot be instantiated.
The specific implementation is very simple:
Ilog log = log4net. logmanager. getlogger ("file"); // introduce log4net // record the error log. error ("err
I uploaded and checked log4net last night, because I was familiar with using this component in Java and have not extended it. However, a small project requires that log4net be rewritten so that log4net can output log messages to the desired place.Let's talk about the use of log4net, and rewrite log4net to print the log messages to what we want.1: Use of log4net:A: Download incubating-log4net-1.2.10.zip, decompress it, find bin \ net \ 2.0 \ release \ log4net. dll (for. Net framework2.0 platforms
Java Logging
Java has a log system (logging framework) that records the runtime information of a program on the JVM ).
The program can use logger (Java. util. Logging. Logger) to record logs.
Java uses a hierarchical naming method (for example, java. AWT) to manage logger. Using logmanager, sub-logger may inherit some attributes from their parent logger ..
Use logger. getlogger (name) to obtain the desired
logs in accordance with user-defined standards.1.2 Configuration MethodsWhen using log4net, you first need to configure how the log is stored, and then call the static method of the Logmanager class in your code Getlog information about the object that holds the object. Where configuration information can be written to the config file, you can also customize an XML document, the specific configuration section information to write to the XML file.Ii.
, content or output of some key data content.
Logger implements the Ilog interface, Ilog defines 5 methods (Debug,inof,warn,error,fatal) to log different log levels separately. There are 5 overloads of these 5 methods. Take debug as an example to illustrate that the others are similar to it.
The Debug method is defined in Ilog as follows:
void Debug(object message);
void Debug(object message, Exception ex);
There is also a Boolean property:
bool IsDebugE
log4net can be categorized by function? It can be done by configuring different logger, and then the function loads Ilog instances according to different loggername. However, because the log configuration of these features is very small, perhaps only the filename is different. So you want to configure it through code, and here's how to share the following If we need to configure different ilog, the process is this, first of all, to create a iloggerrepository, through which log level configurati
Logger hierarchy (Level level)
The logger are all named entities.
Logger names are case-sensitive and follow these rules:
1. If the name of a logger is prefixed by the name of the B logger (by ".") Connection), said a logger is the grandfather class of B logger.
2, if there is no other logger name between the name of a logger and the name of B logger, then a logger is the parent of B-logger.
Example: A logger name is called "Foo.bar", b logger name is called "Foo.Bar.Baz", and A is the parent
implements the Ilog interface, Ilog defines 5 methods (debug,inof,warn,error,fatal) to log logs for different log levels respectively. These 5 methods also have 5 overloads. Let's use debug as an example to illustrate that the others are similar to it.
The Debug method is defined in Ilog as follows:
void Debug (object message);
void Debug (Object message, Exception ex);
There is also a Boolean property:
BOOL isdebugenabled {get;}
If you use Debug (object message, Exception Ex), the log will out
changes to the Logging.properties file, and to record when and who changed which records, what should be done?You can use the PropertyChangeListener provided by the JDK to listen for changes to the Logging.properties file properties.For example, to create a Logpropertylistener class that implements the Java.benas.PropertyChangeListener interface, the PropertyChangeListener interface contains only one PropertyChange (Propertychangeevent) method, the implementation of this method is shown in clea
, password, signin, and signout methods of the user type are all related to objects. To call these attributes and methods, you can only call them by instantiating objects, as shown below:User user = new user ();User. Name = "Bruce Zhang ";User. Password = "password ";User. signin ();User. signout ();
However, when defining a class member, we can also use the static keyword to define some class members irrelevant to the object state, such as the following code:Public class
java.util.logging.LogManagerthe manages the internal Logger hierarchy, and initiates Logger the configuration of the ' s, either through the Configu Ration class or configuration file.There is a single instantiated in the LogManager whole JVM. It's a singleton, in the other words. Here's how to obtain the LogManager instance:Logmanager manager = Logmanager.getlogmanager (); You won't often need to interact
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.