Log4Net configuration

xiaoxiao2021-03-06  42

Logger Hierarchy Logger is an entity that has been named. Logger's name is case sensitive and followed: 1 If a logger name is the prefix of the B logger name (pass "." Connection), said A logger is a grandfather level of B Logger. 2 If a logger's name and the N name of the B logger have no other logger name, a logger is the parent of the B logger. Example: a logger name "foo.bar", the B logger name is "foo.bar.baz", the parent of A is B. Logger named "System" is a grandfather name name "System.Text.StringBuilder". The root logger is located in the top level in the Logger level. It has three rules of exception: 1 root logger exists. 2 Root Logger cannot pass name or taken. 3 Root Logger has a default Level value to debug. Logger can get GetLogger with a statically method of log4net.logmanager class. Level Value: All / debug / info / warn / error / Fatal / Off Level Inheritance Rules: If a logger does not define the level, its Level value will inherit from its parent (defined for Level). The log record request is implemented by calling the output method of the Logger instance. These output methods include Debug, Info, Warn, Error and Fatal. By defining, the output method determines the Level of the log record request. For example, log is a logger instance, then the status log.info (".." log record request Level is Info. If the LEVEL of the log record request is high than the LOGGER itself defines (or inherited), the request is feasible, otherwise it will not be feasible. Simple rules: If the LEVEL of the log record request is L, the Logger itself defines (or inherited) Level is K, when L> = K, log record request is feasible. Level Level: Debug

The Appender log4net allows logs to be output in different ways, such as MS SQL, files, console, or system logs, and more. A logger can have multiple appenders. Each feasible log record request will be output to all appenders, which are referenced in the current logger, including parent loggers. In other words, Appender will add sexual inheritance in the hierarchical level of the logger. For example, a console appender is defined in root, then all Logges have at least one console appender. If a logger has a File appender, a logger and its sub-logger have two appenders. The Additive Property default is True. When set to false, the appender will be overwritten, and no longer inherit from the parent logger. Filters is used to filter the Appender Acceptable log information. Use the following Filter Appender only accepts the log record request between INFO to Fatal.

Use the appender using the following Filter only accepts log records that contain substrings "Database". The first Filter will be in Log Record Information Find "Database", if you find it no longer match the following Filter, APPENER accepts and records the log. If you don't find the second filter, the filter will reject any log information.

Layouts is used to customize the output format.

Load Configuration CONFIGFILE Properties: When we define a log4net configuration file, you can specify the configuration file through this property. ConfigfileExtension properties: This property can be used when the application is compiled into a different extension name. If the Sample program will be compiled into SAMPLE.exe, the configFileExtension is set to "config", then the configuration file name used is: sample.exe.config. Note that it cannot be used simultaneously with the configfile property. Watch properties: Do not monitor the configuration file during the run. When the value is TRUE, FileSystemWatcher will use to monitor the content change, rename, and delete notifications of the configuration file.

Load the log4net configuration for the application, you can set the properties in the application set. For example: [assembly: log4net.config.domconfigurator (configfile = "sample.config")]]]

[Assembly: log4net.config.domconfigurator (configFileExtension = "config")] You can also use any parameters, which will use the application's configuration file. [assmbly: log4net.config.domconfigurator ()]

Another way is to use the Domconfigurator class log4net.config.domconfigurator.configure in the code (

New fileInfo ("TestLogger.exe.config");

Use configureAndWatch (..) to specify a configuration file and monitor changes in the file.

PatternLayout Every specified conversion symbol starts with%, followed by an optional format symbol and a conversion symbol. The conversion symbol is used to specify the data type of the output, such as Level, Logger, Date, etc. For example: conversion model "% -5p [% t]:% m% n" Ilog log = logmanager.getlogger (TestApp)); log.debug ("Message 1); log.warn (" Message 2 ") After the conversion: debug [main]: Message 1 WARN [main]: Message 2 "% -5p" indicates the LEVEL value of the output log record, and the width is 5 sizes, and is aligned.

Conversion symbol list:

a Output the name of AppDomain Creating a log C Default Output Logger's full name. The "{Digital}" can be followed by "{digital}", indicating the Logger name level (starting from the right) corresponding to the output. Such as "a.b.c", "% c {2}" output "B.C" C output call log record request. The "{Digital}" can be followed by "{digital}", indicating the output and the number corresponding to the number (including the namespace, starting from the right). d Output log recording time, follow "{time format}". The default is YYYY-MM-DD HH: MM: SS, FFF F Outputs the full name of the file calling the log record request. (Will affect speed) l Output some local information that calls log record requests. The number of lines such as class and member names, call files and calls declarations. (Extremely influence performance) l The number of declaration code lines that output call log record requests. (Extremely influential performance) m Output information to be output by the application. M Output member names of the call log record request. (Extremely influence performance) N outputs the Level value P outputting the log request of the Log Request

R Output The time (milliseconds) T output from the application starts to the log record request, and if the number of output threads is not named, the number U outputs the name of the current active user. (Principal.Identity.name) W Outputs the Windows ID of the current active user. x

X

% Output one%

转载请注明原文地址:https://www.9cbs.com/read-57514.html

New Post(0)