Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 42736 invoked from network); 18 Jul 2007 15:48:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Jul 2007 15:48:11 -0000 Received: (qmail 28249 invoked by uid 500); 18 Jul 2007 15:47:58 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 28221 invoked by uid 500); 18 Jul 2007 15:47:58 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 28196 invoked by uid 99); 18 Jul 2007 15:47:58 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jul 2007 08:47:58 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of devn.kevin@gmail.com designates 64.233.166.179 as permitted sender) Received: from [64.233.166.179] (HELO py-out-1112.google.com) (64.233.166.179) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jul 2007 08:47:53 -0700 Received: by py-out-1112.google.com with SMTP id f47so475761pye for ; Wed, 18 Jul 2007 08:47:30 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=CnbWzo9m5Ek8KexdTsDpAomvPUqPsXxq4m4t3CPf9k9KfimkjMGokAFz5X3IoiSM0qMVUF10P9wwp3/wmFibJKWlG494+2S/wILLVwvB3PKWRhYb94RdDPZlLgfYMfovfgsc+j9Gmb6WIovHZZ0RTxs7NH3MqFi0ngCPaSVAroE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=OX8fYYLrdTPPUp1/ruHzrLQwBxGaZbcAyBDCfSKV4NzSjUmlrIIB4wuSX/RLnWiyoYvVr7Wwqjs1Ol9DreGxXFUPmbyPUAep5x3Wf8pFa5CdnFvNoI5gR+NqoUhrB3uyYaGwjRYSCMXs8gGQ5nL6UcGfmRdIZNZNNF8iIiKt8Wg= Received: by 10.65.219.20 with SMTP id w20mr1238531qbq.1184773650539; Wed, 18 Jul 2007 08:47:30 -0700 (PDT) Received: by 10.65.75.19 with HTTP; Wed, 18 Jul 2007 08:47:30 -0700 (PDT) Message-ID: Date: Wed, 18 Jul 2007 09:47:30 -0600 From: "Kevin Parkinson" To: "Log4NET User" Subject: Re: Building A Custom Logger In-Reply-To: <2DE096D91923074A82B1E17ADC480EC8FAE885@nasa-dtw-ex004.nasa.cpwr.corp> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_62371_16780810.1184773650485" References: <2DE096D91923074A82B1E17ADC480EC8FAE885@nasa-dtw-ex004.nasa.cpwr.corp> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_62371_16780810.1184773650485 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 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 ------=_Part_62371_16780810.1184773650485 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 ------=_Part_62371_16780810.1184773650485--