How to change the pattern layout of Log4net

by Emanuele 5/2/2008 4:15:00 PM

With Log4net, you can configure the layout of the string that you want to log.
It's very simple, because you can change the pattern layout string in few seconds and without compiling the application.
You don't compile everytime change the pattern layout string, because it is in the application config.
For web application it is in the web.config file and for desktop application it is in the app.config.
Each pattern member starts with % and is followeb by the name of pattern member.
You can change the width, padding, left and right justification for each pattern member.

Sometimes, I use this layout pattern: %type %file %line %method %location %class %C %F %L %l %M %n , but below I explain every single member in order to you can create your pattern layout.

a or appdomain             Friendly name of appdomain
c or logger                    Used to output the logger of the logging event
C or class or type          The fully type name of the caller class
d or date                      The date of logging event in the local time zone
exception                     The exception
F or file                        The file name where the logging request was issued
identity or u                 The active user
l or location                  Location information of the caller
L or line                       The line number from where the logging request was issued
level or p                     The level of the logging event
m or message              Application supplied message associated with the logging event
M or method                The method name where the logging request was issued
n or newline                 Line separator
r or timestamp             The timestamp when the logging request was issued
t or thread                   The name of thread that generated the logging event
username or w            The Windows Identity for active user

 

Tha't all folks!!!

Tags:

Related posts



Powered by BlogEngine.NET 1.3.1.0
Theme by Emanuele Bartolesi

About the author

Name of author Emanuele Bartolesi
I'm a senior developer and project manager.

Contact me Contact me

Calendar

<<  December 2008  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in

Download Day 2008