Table of Contents
Log level
Logger Hierarchy
Logmanager
In this text I'll try to give your an overview of the java.util.logging API. Hopefully it is easier to understand, the individual components once your understand the big picture. Many of the concepts described here is also covered in more details in subsequent texts.Here's an overview diagram of the Java Logging API works:
An overview of the c
STPE.This object is passed to the Logmanager class through the Createlogmanager function. The Scheduler method is called in the Start method in this class to place the Logmanager task into the thread pool. Logmanager The specific task is log reservation, Log refresh, log check these three. The details of these three tasks will be explained in the
prefix of the log file.
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Public class LogManager{Private static string logPath = string. Empty;/// /// Folder for saving logs/// Public static string LogPath{Get{If (logPath = string. Empty){If (System. Web. HttpContext. Current = null)// Windows Forms ApplicationLogPath = AppDomain. CurrentDomain. BaseDirectory;Else// Web applicationLogPath = AppDomain
configuration template /////////////// //////////////////
The subsequent --> Code Use logmanager. getlogger ("subscribehandlerlogger)Note: -->
/// // * End ///////// //////////////////////////
The application is automatically created upon the first access (the application must be run under the system permission or manually created)
The above configuration can be stored in any file
Before log4net starts work, you need to read the config
ArticleDirectory
Add log4net to the Asp.net website
Download Sample Code
There are already many articles about log4net on the Internet.
We have been using it on the web. We used to do winform.ProgramConfiguration once failed! This time, according to the instructions on the Internet, the configuration was successful. We hereby record it!
Add log4net to the C # winform Program
1. Reference log4net. dll
2. Add app. config as follows:
You can find the specific settings
, The utf8 class is used to implement the string. We can also see the Avro schema Declaration and the embedded Enumeration type field.
Gora can easily define different types of data models, such as column data models (hbase, Cassandra), SQL data models, and file models, such as JSON, XML, there are also key-value data models, and the ing between these data models and data storage is defined in an XML file. Each Data Storage abstraction has a corresponding ing format, this ing file declares a ing
The startup of Log4j is controlled by the Logmanager class, and the static block of code in Logmanager determines that it will be loaded when the system is started.
But sometimes in order for it to delay loading, the related variables are passed to the log4j by the spring container, which needs to be loaded after the spring container is started.
Modify the static code block to delete the self-starting part:
exception type.Void Debug (object message, Exception ex );//...
// Boolean attribute is used to check the log level of Logger// (We will see the log level later)Bool isDebugEnabled;Bool isInfoEnabled;//... Boolean attribute corresponding to other methods}The Log4net Framework defines a class called LogManager to manage all logger objects. It has a static GetLogger () method that uses the name parameters we provide to retrieve existing Logger objects.
In the following example, I will create a log that writes logs to the console and the "a. log" file.
[Csharp]Using System;Using System. Collections. Generic;Using System. Linq;Using System. Text;Using log4net;Using log4net. Appender;Using log4net. Layout;Using log4net. Repository. Hierarchy;Namespace MyLog4Net{Public class MyLog4Net{Public static ILog GetMyLog (dynamic LogName){ILog log = null;If (LogName is string){String name = (string) LogName;Log = log4net.
) supported attributes: name and additi.pdf
Required by name. logger name
Optional. The value is true or false. The default value is true. If it is set to false, the appender in the parent logger will be blocked.
(2) supported child elements
Appender-ref: the name of the appender to be referenced.
The evel can be at most one. Only events at this level or above will be recorded.
Param 0 or multiple. Set some parameters.
(3) The
Then, by calling the LogMana
log4net. Config. XmlConfigurator. Configure () at the beginning of the program)• LogManager. GetLogger (typeof (Program). Debug ("info ");. Use LogManager. getLogger transmits the log class name to be recorded to obtain the ILog of this class (so that the log file can see which class is output), and then calls the Debug Method to output the message. Because logs must be printed in more than one place withi
iswarnenabled {Get ;}}
Generally, logmanager. getlogger () is used to obtain a logger. Logmanager maintains a hashtable internally, saves the newly created logger reference, and obtains its instance directly from hashtable when needed next time. Ilog log = logmanager. getlogger (this. GetType ());Log. debug ("aaaaaaaaaaaaaaa ");
All logger parameter settings are
From parentLoggerInheritance level
Root
INFO
INFO
My
None
INFO
My.net
DEBUG
DEBUG
My.net. tcp
None
DEBUG
The corresponding configuration file should be:
In the preceding example, three Logger types are defined and stored in Hierarchy. The three Logger form an inheritance relationship,ChildLoggerAll attributes not defined inMedium inheritance.
Once your application obtains the ILog (that is, the logger agent) through log4ne
( IsLevelEnabled( LogLevel.Debug ) ) { Write( LogLevel.Debug, message, e ); }}
Write Method to Construct log information and output it to system. Console. Out
Private void write (loglevel level, object message, exception E)
In addition, public sealed class nooplogger: ilog is a default log ilog implementation class that does not generate any output.
Ii. Use
The above briefly introduces the main interface of ibatis common logging. Now let's take a look at its usage. Logging is easy
assignment ... */ Bll. ADD (model); Add entity adding system Action Records Log logmanager Log. ADD (model); Update operation: EMPLOYEEBLL BLL = new EMPLOYEEBLL (); Employeemodel model = BLL. Getmodel (EmployeeID); Logmanager Employeemodel modelold = log. Clone (model); Clones the Employeemodel entity object, which is mainly used when the system operations log records /* Model entity after a long as
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.