How to configure the pattern layout of Log4net

By Emanuele Bartolesi at March 20, 2009 04:48
Filed Under: Asp.net, Log, C#

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

Comments

8/30/2009 8:48:48 PM #

amazing stuff thanx Smile

bad credit loans United States

10/4/2009 8:45:44 PM #

Hello Guru, what entice you to post an article. This article was extremely interesting, especially since I was searching for thoughts on this subject last Thursday.

cash advance United States

10/8/2009 11:51:15 AM #

Delighted I encountered this how to entry.  How to configure the pattern layout of  - I have been searching for info on how to address this at the moment  and was drawn by the headline of your posting in Google.  Reading books and papers has not been advantageous but a few web searches has created a result which should assist me a lot.  How could we live without the Internet.  Thanks, I will use the data and must keep your internet site as a bookmark.

soakaway United Kingdom

11/8/2009 2:53:02 AM #

Searching for this for some time now - i guess luck is more advanced than search engines Smile

personal loans United States

11/8/2009 8:52:59 AM #

thanks.  very helpful post!! like the template btw ;)

cash advance United States

11/29/2009 3:05:58 AM #

I found your blog from ask.com and it is very informative. Thank you for sharing such an incredible post..

funny games

12/2/2009 3:05:38 AM #

Hello, just thought you'd be interested to know that I have saved your site to my bookmarks because of your fantastic blog layout (LOL). But honestly, I think your site has one of the cleanest design I've seen yet. It honestly makes your blog post easier to read.

Article Submission United States

12/2/2009 7:43:53 AM #

Hello, just wanted you to know I have saved you to my Google bookmarks because of your fantastic blog layout (LOL). But honestly, I think your blog has one of the cleanest theme I've seen yet. It honestly helps make reading your blog a lot easier.

Article Submission United States

About me

I will also give you some useful tips, based on the modest wisdom gained during the years that I've worked as a developer and project manager.

Widget

Ohloh profile for Emanuele Bartolesi

 

Wakoopa

Software tracking

 

Software tracking

from Amazon



hacker emblem



Scarica il pdf di Game
Rivista Game di videogiochi
Trucchi videogiochi