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 Daniel Williams <dl...@gmail.com> on 2008/07/02 01:40:48 UTC

Must declare a logger in the exe?

I have a dll that I recently put log4net logging into.  It  is called
by many different executables.  So I wanted to find out what is the
minimum I must do so that an exe will cause the logging to happen in
the dll.

Add reference to log4net
Add [assembly:log4net.Config.XmlConfigurator(ConfigFile="log4net.config",
Watch=true)] to the exe's assemblyInfo.cs

That should be it, right?  We've referenced the dll, and called
configure using the assembly attribute.

However, this does not cause my dll to log.  I find that only if I
declare a logger in the exe, only then will the logging in my dll
start.
Does this make sense?  Am I missing something?  I would like to know
the very minimum of code changes required to get logging to work.

Cheers,
Daniel

Re: Must declare a logger in the exe?

Posted by Piers Williams <pi...@gmail.com>.
You need to make a logging call in the exe too (or at least define a logger,
as you say):

"It is necessary that the first call to LogManager.GetLogger made during the
process (or AppDomain) is made from the assembly that has the configuration
attributes"

http://logging.apache.org/log4net/release/faq.html#When%20should%20I%20log%20my%20first%20message?<http://logging.apache.org/log4net/release/faq.html#When%20should%20I%20log%20my%20first%20message>
2008/7/2 Daniel Williams <dl...@gmail.com>:

> I have a dll that I recently put log4net logging into.  It  is called
> by many different executables.  So I wanted to find out what is the
> minimum I must do so that an exe will cause the logging to happen in
> the dll.
>
> Add reference to log4net
> Add [assembly:log4net.Config.XmlConfigurator(ConfigFile="log4net.config",
> Watch=true)] to the exe's assemblyInfo.cs
>
> That should be it, right?  We've referenced the dll, and called
> configure using the assembly attribute.
>
> However, this does not cause my dll to log.  I find that only if I
> declare a logger in the exe, only then will the logging in my dll
> start.
> Does this make sense?  Am I missing something?  I would like to know
> the very minimum of code changes required to get logging to work.
>
> Cheers,
> Daniel
>



-- 
piers
more pedantry at http://piers7.blogspot.com/