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 specifyingAbsoluteTimeDateFormatterDateTimeDateFormatter 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 specifyingAbsoluteTimeDateFormatterDateTimeDateFormatter 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 解析的更多相关文章

  1. 【转载】[C#]Log4net中的RollingFileAppender解析

    Log4日志组件的应用确实简单实用,在比较了企业库和Log4的日志功能后,个人觉得Log4的功能更加强大点.补充说明下,我使用的企业库是2.0版本,Log4net是1.2.1版本的. 在Log4net ...

  2. 使用jsonpath解析json内容

    JsonPath提供的json解析非常强大,它提供了类似正则表达式的语法,基本上可以满足所有你想要获得的json内容.下面我把官网介绍的每个表达式用代码实现,可以更直观的知道该怎么用它. 一.首先需要 ...

  3. springmvc 项目完整示例06 日志–log4j 参数详细解析 log4j如何配置

    Log4j由三个重要的组件构成: 日志信息的优先级 日志信息的输出目的地 日志信息的输出格式 日志信息的优先级从高到低有ERROR.WARN. INFO.DEBUG,分别用来指定这条日志信息的重要程度 ...

  4. log4j源码解析-文件解析

    承接前文log4j源码解析,前文主要介绍了log4j的文件加载方式以及Logger对象创建.本文将在此基础上具体看下log4j是如何解析文件并输出我们所常见的日志格式 附例 文件的加载方式,我们就选举 ...

  5. slf4j和log4j源代码解析以及详解

    备注:下面所有代码以log4j为例 包结构 slf4j-api.jar对外提供api slf4j.log4j12.jar提供适配器 log4j.jar是log4j的jar slf4j初始化 获取ILo ...

  6. Log4j:log4j.properties 配置解析

    Log4j 三个主要组件 Loggers(记录器):记录日志的工具,程序中就是用它来记录我们想要的日志信息. Appenders (输出源):日志输出到什么地方,可以是控制台.文件.流位置.数据库,等 ...

  7. Java日志实战及解析

    Java日志实战及解析 日志是程序员必须掌握的基础技能之一,如果您写的软件没有日志,可以说你没有成为一个真正意义上的程序员. 为什么要记日志? •       监控代码 •       变量变化情况, ...

  8. log4j详细配置解析

    出自:http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记录 ...

  9. Mybatis源码解析,一步一步从浅入深(一):创建准备工程

    Spring SpringMVC Mybatis(简称ssm)是一个很流行的java web框架,而Mybatis作为ORM 持久层框架,因其灵活简单,深受青睐.而且现在的招聘职位中都要求应试者熟悉M ...

随机推荐

  1. 【Android代码片段之六】Toast工具类(实现带图片的Toast消息提示)

    转载请注明出处,原文网址:http://blog.csdn.net/m_changgong/article/details/6841266  作者:张燕广 实现的Toast工具类ToastUtil封装 ...

  2. [Effective JavaScript 笔记]第16条:避免使用eval创建局部变量

    js中的eval函数是一个强大.灵活的工具.强大的工具容易被滥用,所以了解是值得的.(本人只用过它来处理json数据).错误使用eval函数的方式一:允许它干扰作用域.调用eval函数会将其参数作为j ...

  3. meanshift和camshift

    参考:http://www.cnblogs.com/tornadomeet/archive/2012/03/15/2398769.html 照着这位大神的代码运行了一下,发现meanshift的跟踪效 ...

  4. poj1094

    Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29539   Accepted: 10 ...

  5. hdu4255筛素数+广搜

    Mr. B has recently discovered the grid named "spiral grid".Construct the grid like the fol ...

  6. puppet组织架构

    树结构如下: |-- puppet.conf #主配置配置文件 |-- fileserver.conf #文件服务器配置文件 |-- auth.conf #认证配置文件 |-- autosign.co ...

  7. android文章学习 侧滑菜单实现

    http://blog.csdn.net/jj120522/article/details/8075249 http://blog.csdn.net/lilybaobei/article/detail ...

  8. 隐藏Nginx/Apache版本号的安全性与方法

    一.先介绍nginx隐藏版本号的方法. 搭建好nginx或者apache,为了安全起见我们都会隐藏他们的版本号,这边讲的是nginx的版本号,如果你也想隐藏apache的版本号,那请点前面的链接.请看 ...

  9. Ninject学习笔记<一>

    本文转载自永远的阿哲 如果给您带来不便请联系博主. Ninject是一款.Net平台下的开源依赖注入框架.按照官方说法,它快如闪电.超级轻量,且充分利用了.Net的最新语法,使用Lambda表达式代替 ...

  10. 使用WebDriver遇到的那些坑(转)

    http://www.huangbowen.net/blog/2013/06/25/practice-of-webdriver/ 在做web项目的自动化端到端测试时主要使用的是Selenium Web ...