You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Marco Herrn <ma...@sourcepark.org> on 2004/10/13 17:49:28 UTC
How to log to the same Log instance from multiple classes
Hi,
I don't know if the subject makes really clear what I want.
I want to configure log4net only once, usually this way:
this.log= LogManager.GetLogger(typeof(MyClass));
log4net.Config.DOMConfigurator.Configure(new
System.IO.FileInfo("log4net.xml"));
Now I want to log from other classes too, without reconfiguring the
Logger. So all other classes should be able to access log4net by only
calling the first line above. Of course, they should use the same
configuration.
So, how can this be done?
And, btw., do you know way of getting the classname of the current class
dynamically instead of using 'typeof(MyClass)'? I know this isn't
log4net specific, but maybe you can help me here too :-)
Re: How to log to the same Log instance from multiple classes
Posted by DW...@strohlsystems.com.
I normally use a static variable if I want to use the same configuration
across classes. That way I only configure it once.
The way that I use to call the configuration so that it is not hard coded,
but is to be used throughout the assembly is:
log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod.
DeclaringType);
HTH
David Williams
Marco Herrn <ma...@sourcepark.org> wrote on 10/13/2004 11:49:28 AM:
> Hi,
>
> I don't know if the subject makes really clear what I want.
> I want to configure log4net only once, usually this way:
>
> this.log= LogManager.GetLogger(typeof(MyClass));
> log4net.Config.DOMConfigurator.Configure(new
> System.IO.FileInfo("log4net.xml"));
>
> Now I want to log from other classes too, without reconfiguring the
> Logger. So all other classes should be able to access log4net by only
> calling the first line above. Of course, they should use the same
> configuration.
> So, how can this be done?
>
>
> And, btw., do you know way of getting the classname of the current class
> dynamically instead of using 'typeof(MyClass)'? I know this isn't
> log4net specific, but maybe you can help me here too :-)
IMPORTANT: E-mails from this company normally contain confidential material for the sole use of the intended recipient. The use, distribution, transmittal or re-transmittal by an unintended recipient of any communication is prohibited without our express approval in writing or by e-mail. If you are not the intended recipient please contact the sender and delete all copies. All e-mails sent to or from Strohl Systems are to be used for our business purposes only. E-mails sent from or to the company are subject to review by the company.