logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject log4netContrib.AspNetPatternConverters
Date Mon, 23 May 2005 16:16:36 GMT
I've written a collection of PatternConverter classes to make log4net
1.2.9 beta 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, add
additional logging, recompile, then redeploy. The ability to access
sub-properties also exists (i.e. Response.Cookies["UserId"].Domain).

Here are some examples:

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

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

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

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

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

If those names are to long, you can easily rename them to anything
you'd like:

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

<conversionPattern
 value="%p %d %querystring{ProductId} - %m%n" />

<conversionPattern
 value="%p %d %user-identity{Name} - %m%n" />

<conversionPattern
 value="%p %d %user-identity{IsAuthenticated} - %m%n" />

Its also possible to access more than one thing at a time:

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

Here are more complete examples:

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

And source code:

http://www.ronosaurus.com/log4net/log4netContrib.AspNetPatternConverters.zip

This is just the first version so if things aren't doing what you'd
expect, let me know and I'll look into it. Currently, if the requested
item or property cannot be found, an empty string is outputted. 

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

- Ron

Mime
View raw message