ConversionPattern 解析
Sample
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] %X{auth} - Line:%L %m%n" />
%m(message):输出的日志消息
%n(new line):換行
%d(datetime):输出当前语句运行的时刻
%r(run time):输出程序从运行到执行到当前语句时消耗的毫秒数
%t(thread id):当前语句所在的线程ID
%p(priority): 日志的当前优先级别,即DEBUG、INFO、WARN…等
%c(class):当前日志对象的名称
%L:输出语句所在的行号
%F:输出语句所在的文件名
%-数字:表示该项的最小长度,如果不够,则用空格填充
%X:mdc
%x:ndc
官方文档
http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
Conversion Pattern Name |
Effect |
a |
Equivalent to appdomain |
appdomain |
Used to output the friendly name of the AppDomain where the logging event was generated. |
aspnet-cache |
Used to output all cache items in the case of %aspnet-cache or just one named item if used as %aspnet-cache{key} This pattern is not available for Compact Framework or Client Profile assemblies. |
aspnet-context |
Used to output all context items in the case of %aspnet-context or just one named item if used as %aspnet-context{key} This pattern is not available for Compact Framework or Client Profile assemblies. |
aspnet-request |
Used to output all request parameters in the case of %aspnet-request or just one named param if used as %aspnet-request{key} This pattern is not available for Compact Framework or Client Profile assemblies. |
aspnet-session |
Used to output all session items in the case of %aspnet-session or just one named item if used as %aspnet-session{key} This pattern is not available for Compact Framework or Client Profile assemblies. |
c |
Equivalent to logger |
C |
Equivalent to type |
class |
Equivalent to type |
d |
Equivalent to date |
date |
Used to output the date of the logging event in the local time zone. To output the date in universal time use the %utcdate pattern. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %date{HH:mm:ss,fff}or %date{dd MMM yyyy HH:mm:ss,fff}. If no date format specifier is given then ISO8601 format is assumed (Iso8601DateFormatter). The date format specifier admits the same syntax as the time pattern string of theToString. For better results it is recommended to use the log4net date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifyingAbsoluteTimeDateFormatter, DateTimeDateFormatter and respectivelyIso8601DateFormatter. For example, %date{ISO8601} or %date{ABSOLUTE}. These dedicated date formatters perform significantly better than ToString. |
exception |
Used to output the exception passed in with the log message. If an exception object is stored in the logging event it will be rendered into the pattern output with a trailing newline. If there is no exception then nothing will be output and no trailing newline will be appended. It is typical to put a newline before the exception and to have the exception as the last data in the pattern. |
F |
Equivalent to file |
file |
Used to output the file name where the logging request was issued. WARNING Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue. See the note below on the availability of caller location information. |
identity |
Used to output the user name for the currently active user (Principal.Identity.Name). WARNING Generating caller information is extremely slow. Its use should be avoided unless execution speed is not an issue. |
l |
Equivalent to location |
L |
Equivalent to line |
location |
Used to output location information of the caller which generated the logging event. The location information depends on the CLI implementation but usually consists of the fully qualified name of the calling method followed by the callers source the file name and line number between parentheses. The location information can be very useful. However, its generation is extremely slow. Its use should be avoided unless execution speed is not an issue. See the note below on the availability of caller location information. |
level |
Used to output the level of the logging event. |
line |
Used to output the line number from where the logging request was issued. WARNING Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue. See the note below on the availability of caller location information. |
logger |
Used to output the logger of the logging event. The logger conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets. If a precision specifier is given, then only the corresponding number of right most components of the logger name will be printed. By default the logger name is printed in full. For example, for the logger name "a.b.c" the pattern %logger{2} will output "b.c". |
m |
Equivalent to message |
M |
Equivalent to method |
message |
Used to output the application supplied message associated with the logging event. |
mdc |
The MDC (old name for the ThreadContext.Properties) is now part of the combined event properties. This pattern is supported for compatibility but is equivalent to property. |
method |
Used to output the method name where the logging request was issued. WARNING Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue. See the note below on the availability of caller location information. |
n |
Equivalent to newline |
newline |
Outputs the platform dependent line separator character or characters. This conversion pattern offers the same performance as using non-portable line separator strings such as "\n", or "\r\n". Thus, it is the preferred way of specifying a line separator. |
ndc |
Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event. |
p |
Equivalent to level |
P |
Equivalent to property |
properties |
Equivalent to property |
property |
Used to output the an event specific property. The key to lookup must be specified within braces and directly following the pattern specifier, e.g. %property{user} would include the value from the property that is keyed by the string 'user'. Each property value that is to be included in the log must be specified separately. Properties are added to events by loggers or appenders. By default the log4net:HostName property is set to the name of machine on which the event was originally logged. If no key is specified, e.g. %property then all the keys and their values are printed in a comma separated list. The properties of an event are combined from a number of different contexts. These are listed below in the order in which they are searched. the event properties The event has Properties that can be set. These properties are specific to this event only. the thread properties The Properties that are set on the current thread. These properties are shared by all events logged on this thread. the global properties The Properties that are set globally. These properties are shared by all the threads in the AppDomain. |
r |
Equivalent to timestamp |
stacktrace |
Used to output the stack trace of the logging event The stack trace level specifier may be enclosed between braces. For example, %stacktrace{level}. If no stack trace level specifier is given then 1 is assumed Output uses the format: type3.MethodCall3 > type2.MethodCall2 > type1.MethodCall1 This pattern is not available for Compact Framework assemblies. |
stacktracedetail |
Used to output the stack trace of the logging event The stack trace level specifier may be enclosed between braces. For example, %stacktracedetail{level}. If no stack trace level specifier is given then 1 is assumed Output uses the format: type3.MethodCall3(type param,...) > type2.MethodCall2(type param,...) > type1.MethodCall1(type param,...) This pattern is not available for Compact Framework assemblies. |
t |
Equivalent to thread |
timestamp |
Used to output the number of milliseconds elapsed since the start of the application until the creation of the logging event. |
thread |
Used to output the name of the thread that generated the logging event. Uses the thread number if no name is available. |
type |
Used to output the fully qualified type name of the caller issuing the logging request. This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets. If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. By default the class name is output in fully qualified form. For example, for the class name "log4net.Layout.PatternLayout", the pattern %type{1}will output "PatternLayout". WARNING Generating the caller class information is slow. Thus, its use should be avoided unless execution speed is not an issue. See the note below on the availability of caller location information. |
u |
Equivalent to identity |
username |
Used to output the WindowsIdentity for the currently active user. WARNING Generating caller WindowsIdentity information is extremely slow. Its use should be avoided unless execution speed is not an issue. |
utcdate |
Used to output the date of the logging event in universal time. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %utcdate{HH:mm:ss,fff} or %utcdate{dd MMM yyyy HH:mm:ss,fff}. If no date format specifier is given then ISO8601 format is assumed (Iso8601DateFormatter). The date format specifier admits the same syntax as the time pattern string of theToString. For better results it is recommended to use the log4net date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifyingAbsoluteTimeDateFormatter, DateTimeDateFormatter and respectivelyIso8601DateFormatter. For example, %utcdate{ISO8601} or%utcdate{ABSOLUTE}. These dedicated date formatters perform significantly better than ToString. |
w |
Equivalent to username |
x |
Equivalent to ndc |
X |
Equivalent to mdc |
% |
The sequence %% outputs a single percent sign. |
ConversionPattern 解析的更多相关文章
- 【转载】[C#]Log4net中的RollingFileAppender解析
Log4日志组件的应用确实简单实用,在比较了企业库和Log4的日志功能后,个人觉得Log4的功能更加强大点.补充说明下,我使用的企业库是2.0版本,Log4net是1.2.1版本的. 在Log4net ...
- 使用jsonpath解析json内容
JsonPath提供的json解析非常强大,它提供了类似正则表达式的语法,基本上可以满足所有你想要获得的json内容.下面我把官网介绍的每个表达式用代码实现,可以更直观的知道该怎么用它. 一.首先需要 ...
- springmvc 项目完整示例06 日志–log4j 参数详细解析 log4j如何配置
Log4j由三个重要的组件构成: 日志信息的优先级 日志信息的输出目的地 日志信息的输出格式 日志信息的优先级从高到低有ERROR.WARN. INFO.DEBUG,分别用来指定这条日志信息的重要程度 ...
- log4j源码解析-文件解析
承接前文log4j源码解析,前文主要介绍了log4j的文件加载方式以及Logger对象创建.本文将在此基础上具体看下log4j是如何解析文件并输出我们所常见的日志格式 附例 文件的加载方式,我们就选举 ...
- slf4j和log4j源代码解析以及详解
备注:下面所有代码以log4j为例 包结构 slf4j-api.jar对外提供api slf4j.log4j12.jar提供适配器 log4j.jar是log4j的jar slf4j初始化 获取ILo ...
- Log4j:log4j.properties 配置解析
Log4j 三个主要组件 Loggers(记录器):记录日志的工具,程序中就是用它来记录我们想要的日志信息. Appenders (输出源):日志输出到什么地方,可以是控制台.文件.流位置.数据库,等 ...
- Java日志实战及解析
Java日志实战及解析 日志是程序员必须掌握的基础技能之一,如果您写的软件没有日志,可以说你没有成为一个真正意义上的程序员. 为什么要记日志? • 监控代码 • 变量变化情况, ...
- log4j详细配置解析
出自:http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记录 ...
- Mybatis源码解析,一步一步从浅入深(一):创建准备工程
Spring SpringMVC Mybatis(简称ssm)是一个很流行的java web框架,而Mybatis作为ORM 持久层框架,因其灵活简单,深受青睐.而且现在的招聘职位中都要求应试者熟悉M ...
随机推荐
- IOS开发的目录结构
http://www.itjhwd.com/iosmolukaifa/ 目录结构 个人总结: =============================================== ...
- glut64位操作系统安装
64位win7下OpenGL的配置 - walkandthink的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/walkandthink/article/detai ...
- C++文件输入输出
#include <iostream> //有些系统里面可以省略此头文件 #include <fstream> #include <string> int main ...
- Java for LeetCode 144 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary t ...
- Java for LeetCode 143 Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do th ...
- [Eclipse] Eclipse中,Add Jars与Add Library的区别
refer to : http://blog.csdn.net/gaojinshan/article/details/16948075 Eclipse中,工程属性的Java Build Path的Li ...
- glut编译问题 (程序无法运行)
参考:http://blog.csdn.net/robinjwong/article/details/5636049 error: the procedure entry point _glutini ...
- ping 有端口的ip
使用工具 tcping 使用方法,将此工具放在C:/Windows/System32 目录下, 在cmd 中: tcping 127.0.0.1 8080
- NEXTDAY
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "com_time ...
- Linux命令行下创建纳入版本控制下的新目录
[root@ok 资料库]# svn mkdir test A test [root@ok 资料库]# svn ci -m "mkdir test" Adding 资料库/test ...