> -----Original Message-----
> From: Ron Grabowski [mailto:[EMAIL PROTECTED]
> Sent: 24 June 2005 14:49
> To: Log4NET User
> Subject: Re: Customized log4net, would like feedback/advice
>
> Here's another example of extending the ILog interface to
> accept additional parameters:
>
> http://tinyurl.com/cpz5o
> http://cvs.apache.org/viewcvs.cgi/logging-log4net/extensions/n
et/1.0/log4net.Ext.EventID/cs/src/IEventIDLog.cs?view=markup
>
> If you made an overload like this:
>
> log.Error(string, Exception, params object[]);
I think that for now the right way to do this is with an extension.
Something along the lines of the EventID extension that Ron has linked
to above.
> Sometimes I wonder why the MDC (or ThreadContext) doesn't
> support this style of (IDisposable?) notation:
>
> using(log4net.MDC.Set("LogData", myData)
> using(log4net.MDC.Set("LogException", e) {
> log.Info("An exception occured.");
> }
>
> That may or may not be easier to read. I believe NDC calls
> support that notation. I'm sure there's some good reason why
> that syntax isn't supported :-)
The ThreadContext stacks (NDC) support the IDisposable pattern because
the items pushed into the stack must be removed from the stack when they
are no longer relevant. Typically the stack is used along the same lines
as the method call stack, some contextual information is available in
one method and you want to include it in all logs made by sub-methods.
This lends itself very well to the C# using pattern.
The Global/Thread/Event context properties are really intended to be set
once and not cleared. Global properties should represent global state,
they should be set early on in the application's lifecycle and can be
updated when that state changes. Thread properties are intended to be
set to differentiate one thread from another. Event properties are
intended to hold event specific values.
The ThreadContext properties are not intended to be used to set event
specific values, and therefore do not support a shorthand for removing
the property value. The fact that they are used for this purpose
suggests that the APIs available for setting the event properties are
not sufficient, and I agree that they could be improved along the lines
suggested by Frode and Ron.
Also it is worth noting that supporting the using pattern is not free,
it requires the creation of an IDisposable object that can be returned,
and also this cost is not something that is enabled or disabled through
the logging config, the contexts are always enabled because you could
enable logging at some point.
Cheers,
Nicko