logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Parkinson" <devn.ke...@gmail.com>
Subject Re: Building A Custom Logger
Date Wed, 18 Jul 2007 15:47:30 GMT
Bless you, John Vanderkolk!

I have chosen to use:

    public InterfaceImpl(Type type) : base
(log4net.LogManager.GetLogger(type).Logger)
{ }

    IInterface _logger = new InterfaceImpl(typeof(MyClass));

...this makes a lot of sense and it works!

On 7/18/07, Vanderkolk, John <John.Vanderkolk@compuware.com> wrote:
>
>  The cleanest way of doing this would be to implement your own LogManager.
> However if you really don't want to do that and want to just have your
> IInterface and InterfaceImpl, the best way I see would be to make sure your
> InterfaceImpl constructor is public and use log4net's LogManager to get an
> ILog, and use its ILogger to initialize your InterfaceImpl:
>
>     IInterface _logger = new InterfaceImpl(log4net.LogManager
> (typeof(MyClass)).Logger);
>
> A cleaner way would be to add a new constructor to your InterfaceImpl:
>
>     public InterfaceImpl(Type type) : base (log4net.LogManager.GetLogger(type).Logger)
> { }
>
> so that you can do this:
>
>     IInterface _logger = new InterfaceImpl(typeof(MyClass));
>
>
> John VanderKolk
>
>
>
> The contents of this e-mail are intended for the named addressee only. It
> contains information that may be confidential. Unless you are the named
> addressee or an authorized designee, you may not copy or use it, or disclose
> it to anyone else. If you received it in error please notify us immediately
> and then destroy it.
>
> *From:* Kevin Parkinson [mailto:devn.kevin@gmail.com]
> *Sent:* Tuesday, July 17, 2007 7:04 PM
> *To:* log4net-user@logging.apache.org
> *Subject:* Building A Custom Logger
>
> Has anyone had experience building a custom logger?
>
> Here is what I am doing. I have created my own interface describing what
> the kinds of things a logger needs to be able to log in my environment
> (let's call it IInterface) like security audits, performance statistics,
> etc. This interface extends ILog as well.
> Thus: IInterface : ILog
>
> Then, I have an implementation of IInterface and we'll call that
> InterfaceImpl which also inherits from LogImpl (in order to satisfy the ILog
> interface).
> Like so: InterfaceImpl : LogImpl, IInterface
>
> Now, when I go to put a logger in a class in which I want to perform
> logging, by default I would usually put the line of code:
> ILog _logger = LogManager.GetLogger(typeof(MyClass));
>
> What I would like to do is to be able to say:
> IInterface _logger = LogManager.GetLogger(typeof(MyClass));
>
> ...but this does not work (nor does anything else I have tried) because
> GetLogger returns LogImpl which knows nothing of my IInterface.
>
> Can anyone recommend anything that I can try without needing to modify the
> LogManager (a sealed class)?
>
>


-- 
Kevin Parkinson
Musician / Software Developer
Edmonton Alberta Canada

Mime
View raw message