You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Tim Bond <tb...@smallworldlegal.com> on 2016/03/12 22:35:10 UTC

Enhancement Suggestion

I suspect that someone has proposed this before but I would like to suggest
making Contexts plug-able.  The three existing contexts are useful but
there is at least one that I think would be much more useful, namely,
HttpRequestContext.  Obviously that does not have universal appeal hence
the suggestion to create plug-able Contexts that would allow extensions
like this for certain scenarios.
To do this would require giving a priority to all the contexts so that new
contexts could be inserted at different levels.  Also defining an interface
that could be used to access properties by the log4net core.
I would be happy to contribute some code for this but I wanted to get some
feedback before actually going to the trouble of writing the code.

Tim

Re: Enhancement Suggestion

Posted by Tim Bond <tb...@computer.org>.
This is all just pseudo code so don't read into much.  This is just broad
strokes.

I would like to create an interface

IContext
{
ReadOnlyPropertyDictionary Properties
}

Not sure where this should live but maybe on a repository we have a
property:
IOrderedCollection<IContext> Contexts;

The CreateCompositeProperties method of LoggingEvent then becomes something
like

CreateCompositeProperties()
{
m_compositeProperties = new CompositeProperties();

foreach(var context in m_repository.Contexts)
{
m_compositeProperties.Add(context.Properties);
}
}

That achieves the core goal of making the Contexts plugable but leaves work
implementing the individual implementations of Contexts.

That doesn't seem too bad though.  For the GlobalContext:

public class GlobalContextImpl : IContext
{
public ReadOnlyPropertyDictionary Properties
{
get {return GlobalContext.Properties.GetReadOnlyProperties();}
}
}

The pattern would be very similar for ThreadContext and
LogicalThreadContext.

The pattern for new Contexts should probably be very similar to the
existing contexts.  Access is provided through a static class that does the
work of storing properties in the correct context.  I have a implementation
of HttpRequestContext that uses the HttpContext to store property values.

The final piece of the puzzle is to provide the configuration support to
enable the Contexts property to be created.
I was thinking of something like:
<context type="name,assembly" priority="n" />

The existing contexts would have predefined priorities.  We might provide a
mechanism that the existing priorities could be disabled.

Any comments on this would be much appreciated.

Tim


On Sun, Mar 13, 2016 at 5:58 AM Dominik Psenner <dp...@gmail.com> wrote:

> Hi
>
> Sounds great. Yet this has to be thought well before the first line of
> code is to be written. Who does add contexts and how can they be retrieved?
> Where are the scopes of the contexts? Are they supposed to travel along
> with events sent to remote sinks?
>
> Cheers
> On 12 Mar 2016 10:35 p.m., "Tim Bond" <tb...@smallworldlegal.com> wrote:
>
>> I suspect that someone has proposed this before but I would like to
>> suggest making Contexts plug-able.  The three existing contexts are useful
>> but there is at least one that I think would be much more useful, namely,
>> HttpRequestContext.  Obviously that does not have universal appeal hence
>> the suggestion to create plug-able Contexts that would allow extensions
>> like this for certain scenarios.
>> To do this would require giving a priority to all the contexts so that
>> new contexts could be inserted at different levels.  Also defining an
>> interface that could be used to access properties by the log4net core.
>> I would be happy to contribute some code for this but I wanted to get
>> some feedback before actually going to the trouble of writing the code.
>>
>> Tim
>>
>

Re: Enhancement Suggestion

Posted by Dominik Psenner <dp...@gmail.com>.
Hi

Sounds great. Yet this has to be thought well before the first line of code
is to be written. Who does add contexts and how can they be retrieved?
Where are the scopes of the contexts? Are they supposed to travel along
with events sent to remote sinks?

Cheers
On 12 Mar 2016 10:35 p.m., "Tim Bond" <tb...@smallworldlegal.com> wrote:

> I suspect that someone has proposed this before but I would like to
> suggest making Contexts plug-able.  The three existing contexts are useful
> but there is at least one that I think would be much more useful, namely,
> HttpRequestContext.  Obviously that does not have universal appeal hence
> the suggestion to create plug-able Contexts that would allow extensions
> like this for certain scenarios.
> To do this would require giving a priority to all the contexts so that new
> contexts could be inserted at different levels.  Also defining an interface
> that could be used to access properties by the log4net core.
> I would be happy to contribute some code for this but I wanted to get some
> feedback before actually going to the trouble of writing the code.
>
> Tim
>