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:

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

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

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

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

 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:

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

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

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

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

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

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

Here are more complete examples:


And source code:


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

View raw message