Hello. In response to Nicko's reply to my first post on the log4net
list:

http://tinyurl.com/a24cc
http://www.mail-archive.com/log4net-user%40logging.apache.org/msg00886.html

I've written a collection of PatternConverter classes to make log4net
play nicely with Asp.Net. They allow for properties of the Application,
Cache, Context, HttpRuntime, Request, Response, and Session to be used
to configure log4net. Values from these objects may also be inserted
into log messages without first having to place the items in the MDC in
code. This may offer more run-time style debugging of applications
without having to take the application down and add additional logging
statements. The ability to access sub-properties also exists (i.e.
Response.Cookies). Here are some quick examples followed by more
detailed examples followed by some questions. The aspnet- style naming
was based on a certain other .Net logger whose name begins with an "N"
and ends with "Log".

<conversionPattern
value="%aspnet-httpRuntime{AppDomainAppPath}\Logs\log.txt" />

<conversionPattern value="%p %d %aspnet-request{RawUrl} - %m%n" />

<conversionPattern value="%p %d
%aspnet-request-form{txtDateLastUpdated} - %m%n" />

<conversionPattern value="%p %d %aspnet-response{ContentType}
%aspnet-response-cookies{MyCookie} - %m%n" />

<conversionPattern value="%p %d %aspnet-context{TimeStamp} - %m%n" />

<conversionPattern value="%p %d %aspnet-response-cookies{MyCookie} -
%m%n" />

Here is a complete list of classes in the AspNetPatternConveters
namespace:

 ApplicationPatternConverter
 CachePatternConverter
 ContextPatternConverter
 ContextPatternConverter+Items
 ContextPatternConverter+User
 HttpRuntimePatternConverter
 RequestPatternConverter
 RequestPatternConverter+QueryString
 RequestPatternConverter+Form
 RequestPatternConverter+ServerVariables
 RequestPatternConverter+Cookies
 RequestPatternConverter+Params
 ResponsePatternConverter
 ResponsePatternConverter+Cache+VaryByHeaders
 ResponsePatternConverter+Cache+VaryByParams
 ResponsePatternConverter+Cookies
 ResponsePatternConverter+ContextEncoding
 SessionPatternConverter
 SessionPatternConverter+Contents

I won't list every possible property in this email but just about
everything is exposed to log4net:

 Context.IsCustomErrorEnabled
 Context.IsDebuggingEnabled
 Context.SkipAuthorization
 Context.Timestamp
 Context.Items
 Context.User.Identity
 HttpRuntime.AppDomainAppPath
 HttpRuntime.AppDomainAppVirtualPath
 Request.ApplicationPath
 Request.ContentLength
 Response.Cookies
 Response.QueryString
 ...

A more complete example of the first part of this email can be found
here:

 http://www.ronosaurus.com/log4net/AspNetPatternConverters1.txt

If this issue is addressed:

 http://issues.apache.org/jira/browse/LOG4NET-30

The file could be shortened to just:

 http://www.ronosaurus.com/log4net/AspNetPatternConverters2.txt

The classes follow this style of coding to allow access to properties:

 http://www.ronosaurus.com/log4net/ContextPatternConverter.png

This style of coding is used to allow access to collection-like
objects:

 http://www.ronosaurus.com/log4net/QueryString.txt

This issue is preventing me from specifing what property of a Cookie
(i.e. Domain, Value, etc.) should appear in the log file:
 
 http://issues.apache.org/jira/browse/LOG4NET-31

Now for some questions...

Should there be try/catch blocks around the code or is checking for
null values good enough?

I'm not sure how to handle access to certain properties like the Count
property of the Cache object. If I use this conversion pattern:

 <conversionPattern value="%cache{Count} - %m%n" />

I'm unable to determine which of the following the user wants
displayed:

 Cache.Count
 Cache["Count"]

Is there a more appropriate naming convention for my classes? The
design for the inner classes is based off of FileAppender's inner file
locking classes.

I'd like to hear some feedback and have an chance to make somemore
minor changes to the code before I make it availabe for download.

Comments, questions, cool, not cool, don't care? 

- Ron

Reply via email to