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 minherz <mi...@gmail.com> on 2007/04/30 12:07:25 UTC

3rd party assembly logging configuration

Hello. I failed finding a clear answer to my question here, though there are
several posts that touching the subject.
I have a set of shared assembly which use log4net. However, the application
does not have to use it as well i do not want that the log4net configuration
of the application will dictate logging behavior of the shared assembly. In
the case the developer wants to output log from the shared assembly he will
have to define a separate configuration file. While the file is not there no
logging should be performed by the shared assembly.
I tried defining XmlConfiguration attribute with explicit config file name
in the AssemblyInfo of my shared library. It is either ignored or does not
work for other reason. All the output is displayed according to root
configuration of the application.
I know that i can filter it out by using logger element, but i have
different requirement.
I found several articles that suggest using in code call for configuration.
My problem is that the shared assembly is a class library which provide a
collection of classes and i have no idea which of them will be created
first. I also can not define some initialization method as it is against the
design requirements.
Can anybody advise how i can solve this matter?
-- 
View this message in context: http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813.html#a10251023
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by minherz <mi...@gmail.com>.
It does not work, though i configured all like in the example.
The internal debugging display that my library has no repository attribute.
I defined it as [assembly:
log4net.Config.Repository("RootNameSpaceOfTheLibrary")]
inside the AssemblyInfo.cs file and before the log4net.Config.XmlConfigurer
attribute.


nicko wrote:
> 
> The log4net internal debugging can be enabled by setting an <appSetting>
> in the application's config file:
> 
> <appSettings>
>   <add key="log4net.Internal.Debug" value="true"/>
> </appSettings>
> 
> This must go into the applications .config file (or if it is a web app
> then the Web.config file).
> 
> 
> Setting the XmlConfigurator attribute on your assembly should cause it
> to load its configuration separately from the main application.
> 
> There is an example application that is included in the log4net download
> that shows this behaviour.
> 
> examples\net\1.0\Repository
> 
> This is made up of 3 assemblies.
> 
> SharedModule - this is an ordinary DLL, it uses logging, but does not
> configure it.
> SimpleApp - this is an EXE, it configures and uses logging.
> SimpleModule - this is a DLL, that setups its own repository and
> configures it.
> 
> To see the RepositoryAttribute and XmlConfiguratorAttribute have a look
> at this example source file:
> 
> examples\net\1.0\Repository\SimpleModule\cs\src\Math.cs
> 
> Cheers,
> Nicko
> ------------
> Nicko Cadell
> log4net development
> http://logging.apache.org/log4net
> 
> -----Original Message-----
> From: minherz [mailto:minherz@gmail.com] 
> Sent: 01 May 2007 12:38
> To: log4net-user@logging.apache.org
> Subject: RE: 3rd party assembly logging configuration
> 
> 
> The subject of using repository is little cloudy for me, even after
> reading
> documentation. If i want to have same hierarchical repository for my
> library
> but starting from different root, then i have to use Repository
> attribute at
> the assembly level of my library. Is it correct?
> Do i have to enable internal debugging of log4net in both configuration
> files or only in the application's configuration?
> After i make use of different repository does the XmlConfigurer
> attribute in
> the assembly level of my library enough to force log4net loading
> configuration from the different file?
> 
> Thank you.
> -- 
> View this message in context:
> http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
> .html#a10267809
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813.html#a10268789
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by ni...@apache.org.
The root logger's name is NULL rather than empty, that is why you need
to configure it in the log4net XML config using the <root> element
rather than the <logger name=3D""> element. A logger with empty name
would be a child of the root logger.

The logger hierarchy exists within the repository. If you create your
own repository then it is completely separate to the repository and
logger hierarchy used in the main application.

Cheers,
Nicko

------------
Nicko Cadell
log4net development
http://logging.apache.org/log4net

-----Original Message-----
From: minherz [mailto:minherz@gmail.com] 
Sent: 01 May 2007 14:31
To: log4net-user@logging.apache.org
Subject: RE: 3rd party assembly logging configuration


I assume that root logger's name is empty string, so any type name used
for
logger creation will be treated according to hierarchical rules and
independent from the "main" application.

And thank you again for fast and clear answers.


nicko wrote:
> 
> I'm not exactly sure I understand the question, but log4net supports a
> hierarchy of loggers regardless of the RepositoryAttribute, there
should
> be no change in this behaviour.
> 
> The name of the repository does not have to match up to the name of
your
> assembly or any of your namespaces, it is just used to identify a
> repository in the process.
> 
> Nicko
> 
> ------------
> Nicko Cadell
> log4net development
> http://logging.apache.org/log4net
> 
> -----Original Message-----
> From: minherz [mailto:minherz@gmail.com] 
> Sent: 01 May 2007 14:15
> To: log4net-user@logging.apache.org
> Subject: RE: 3rd party assembly logging configuration
> 
> 
> Thank you. I still must check it but it seems to be working.
> Can you answer me to a question about hierarchy support when using
> repository attribute?
> Will log4net support the hierarchical loggers within library's
> configuration
> if i setup a repository using the topmost namespace name of the
library?
> 
> 
> nicko wrote:
>> 
>> The log4net internal debugging can be enabled by setting an
> <appSetting>
>> in the application's config file:
>> 
>> <appSettings>
>>   <add key="log4net.Internal.Debug" value="true"/>
>> </appSettings>
>> 
>> This must go into the applications .config file (or if it is a web
app
>> then the Web.config file).
>> 
>> 
>> Setting the XmlConfigurator attribute on your assembly should cause
it
>> to load its configuration separately from the main application.
>> 
>> There is an example application that is included in the log4net
> download
>> that shows this behaviour.
>> 
>> examples\net\1.0\Repository
>> 
>> This is made up of 3 assemblies.
>> 
>> SharedModule - this is an ordinary DLL, it uses logging, but does not
>> configure it.
>> SimpleApp - this is an EXE, it configures and uses logging.
>> SimpleModule - this is a DLL, that setups its own repository and
>> configures it.
>> 
>> To see the RepositoryAttribute and XmlConfiguratorAttribute have a
> look
>> at this example source file:
>> 
>> examples\net\1.0\Repository\SimpleModule\cs\src\Math.cs
>> 
>> Cheers,
>> Nicko
>> ------------
>> Nicko Cadell
>> log4net development
>> http://logging.apache.org/log4net
>> 
>> -----Original Message-----
>> From: minherz [mailto:minherz@gmail.com] 
>> Sent: 01 May 2007 12:38
>> To: log4net-user@logging.apache.org
>> Subject: RE: 3rd party assembly logging configuration
>> 
>> 
>> The subject of using repository is little cloudy for me, even after
>> reading
>> documentation. If i want to have same hierarchical repository for my
>> library
>> but starting from different root, then i have to use Repository
>> attribute at
>> the assembly level of my library. Is it correct?
>> Do i have to enable internal debugging of log4net in both
> configuration
>> files or only in the application's configuration?
>> After i make use of different repository does the XmlConfigurer
>> attribute in
>> the assembly level of my library enough to force log4net loading
>> configuration from the different file?
>> 
>> Thank you.
>> -- 
>> View this message in context:
>>
>
http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
>> .html#a10267809
>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
> .html#a10268921
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
.html#a10269093
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by minherz <mi...@gmail.com>.
I assume that root logger's name is empty string, so any type name used for
logger creation will be treated according to hierarchical rules and
independent from the "main" application.

And thank you again for fast and clear answers.


nicko wrote:
> 
> I'm not exactly sure I understand the question, but log4net supports a
> hierarchy of loggers regardless of the RepositoryAttribute, there should
> be no change in this behaviour.
> 
> The name of the repository does not have to match up to the name of your
> assembly or any of your namespaces, it is just used to identify a
> repository in the process.
> 
> Nicko
> 
> ------------
> Nicko Cadell
> log4net development
> http://logging.apache.org/log4net
> 
> -----Original Message-----
> From: minherz [mailto:minherz@gmail.com] 
> Sent: 01 May 2007 14:15
> To: log4net-user@logging.apache.org
> Subject: RE: 3rd party assembly logging configuration
> 
> 
> Thank you. I still must check it but it seems to be working.
> Can you answer me to a question about hierarchy support when using
> repository attribute?
> Will log4net support the hierarchical loggers within library's
> configuration
> if i setup a repository using the topmost namespace name of the library?
> 
> 
> nicko wrote:
>> 
>> The log4net internal debugging can be enabled by setting an
> <appSetting>
>> in the application's config file:
>> 
>> <appSettings>
>>   <add key="log4net.Internal.Debug" value="true"/>
>> </appSettings>
>> 
>> This must go into the applications .config file (or if it is a web app
>> then the Web.config file).
>> 
>> 
>> Setting the XmlConfigurator attribute on your assembly should cause it
>> to load its configuration separately from the main application.
>> 
>> There is an example application that is included in the log4net
> download
>> that shows this behaviour.
>> 
>> examples\net\1.0\Repository
>> 
>> This is made up of 3 assemblies.
>> 
>> SharedModule - this is an ordinary DLL, it uses logging, but does not
>> configure it.
>> SimpleApp - this is an EXE, it configures and uses logging.
>> SimpleModule - this is a DLL, that setups its own repository and
>> configures it.
>> 
>> To see the RepositoryAttribute and XmlConfiguratorAttribute have a
> look
>> at this example source file:
>> 
>> examples\net\1.0\Repository\SimpleModule\cs\src\Math.cs
>> 
>> Cheers,
>> Nicko
>> ------------
>> Nicko Cadell
>> log4net development
>> http://logging.apache.org/log4net
>> 
>> -----Original Message-----
>> From: minherz [mailto:minherz@gmail.com] 
>> Sent: 01 May 2007 12:38
>> To: log4net-user@logging.apache.org
>> Subject: RE: 3rd party assembly logging configuration
>> 
>> 
>> The subject of using repository is little cloudy for me, even after
>> reading
>> documentation. If i want to have same hierarchical repository for my
>> library
>> but starting from different root, then i have to use Repository
>> attribute at
>> the assembly level of my library. Is it correct?
>> Do i have to enable internal debugging of log4net in both
> configuration
>> files or only in the application's configuration?
>> After i make use of different repository does the XmlConfigurer
>> attribute in
>> the assembly level of my library enough to force log4net loading
>> configuration from the different file?
>> 
>> Thank you.
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
>> .html#a10267809
>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
> .html#a10268921
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813.html#a10269093
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by ni...@apache.org.
I'm not exactly sure I understand the question, but log4net supports a
hierarchy of loggers regardless of the RepositoryAttribute, there should
be no change in this behaviour.

The name of the repository does not have to match up to the name of your
assembly or any of your namespaces, it is just used to identify a
repository in the process.

Nicko

------------
Nicko Cadell
log4net development
http://logging.apache.org/log4net

-----Original Message-----
From: minherz [mailto:minherz@gmail.com] 
Sent: 01 May 2007 14:15
To: log4net-user@logging.apache.org
Subject: RE: 3rd party assembly logging configuration


Thank you. I still must check it but it seems to be working.
Can you answer me to a question about hierarchy support when using
repository attribute?
Will log4net support the hierarchical loggers within library's
configuration
if i setup a repository using the topmost namespace name of the library?


nicko wrote:
> 
> The log4net internal debugging can be enabled by setting an
<appSetting>
> in the application's config file:
> 
> <appSettings>
>   <add key="log4net.Internal.Debug" value="true"/>
> </appSettings>
> 
> This must go into the applications .config file (or if it is a web app
> then the Web.config file).
> 
> 
> Setting the XmlConfigurator attribute on your assembly should cause it
> to load its configuration separately from the main application.
> 
> There is an example application that is included in the log4net
download
> that shows this behaviour.
> 
> examples\net\1.0\Repository
> 
> This is made up of 3 assemblies.
> 
> SharedModule - this is an ordinary DLL, it uses logging, but does not
> configure it.
> SimpleApp - this is an EXE, it configures and uses logging.
> SimpleModule - this is a DLL, that setups its own repository and
> configures it.
> 
> To see the RepositoryAttribute and XmlConfiguratorAttribute have a
look
> at this example source file:
> 
> examples\net\1.0\Repository\SimpleModule\cs\src\Math.cs
> 
> Cheers,
> Nicko
> ------------
> Nicko Cadell
> log4net development
> http://logging.apache.org/log4net
> 
> -----Original Message-----
> From: minherz [mailto:minherz@gmail.com] 
> Sent: 01 May 2007 12:38
> To: log4net-user@logging.apache.org
> Subject: RE: 3rd party assembly logging configuration
> 
> 
> The subject of using repository is little cloudy for me, even after
> reading
> documentation. If i want to have same hierarchical repository for my
> library
> but starting from different root, then i have to use Repository
> attribute at
> the assembly level of my library. Is it correct?
> Do i have to enable internal debugging of log4net in both
configuration
> files or only in the application's configuration?
> After i make use of different repository does the XmlConfigurer
> attribute in
> the assembly level of my library enough to force log4net loading
> configuration from the different file?
> 
> Thank you.
> -- 
> View this message in context:
>
http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
> .html#a10267809
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
.html#a10268921
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by minherz <mi...@gmail.com>.
Thank you. I still must check it but it seems to be working.
Can you answer me to a question about hierarchy support when using
repository attribute?
Will log4net support the hierarchical loggers within library's configuration
if i setup a repository using the topmost namespace name of the library?


nicko wrote:
> 
> The log4net internal debugging can be enabled by setting an <appSetting>
> in the application's config file:
> 
> <appSettings>
>   <add key="log4net.Internal.Debug" value="true"/>
> </appSettings>
> 
> This must go into the applications .config file (or if it is a web app
> then the Web.config file).
> 
> 
> Setting the XmlConfigurator attribute on your assembly should cause it
> to load its configuration separately from the main application.
> 
> There is an example application that is included in the log4net download
> that shows this behaviour.
> 
> examples\net\1.0\Repository
> 
> This is made up of 3 assemblies.
> 
> SharedModule - this is an ordinary DLL, it uses logging, but does not
> configure it.
> SimpleApp - this is an EXE, it configures and uses logging.
> SimpleModule - this is a DLL, that setups its own repository and
> configures it.
> 
> To see the RepositoryAttribute and XmlConfiguratorAttribute have a look
> at this example source file:
> 
> examples\net\1.0\Repository\SimpleModule\cs\src\Math.cs
> 
> Cheers,
> Nicko
> ------------
> Nicko Cadell
> log4net development
> http://logging.apache.org/log4net
> 
> -----Original Message-----
> From: minherz [mailto:minherz@gmail.com] 
> Sent: 01 May 2007 12:38
> To: log4net-user@logging.apache.org
> Subject: RE: 3rd party assembly logging configuration
> 
> 
> The subject of using repository is little cloudy for me, even after
> reading
> documentation. If i want to have same hierarchical repository for my
> library
> but starting from different root, then i have to use Repository
> attribute at
> the assembly level of my library. Is it correct?
> Do i have to enable internal debugging of log4net in both configuration
> files or only in the application's configuration?
> After i make use of different repository does the XmlConfigurer
> attribute in
> the assembly level of my library enough to force log4net loading
> configuration from the different file?
> 
> Thank you.
> -- 
> View this message in context:
> http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
> .html#a10267809
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813.html#a10268921
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by ni...@apache.org.
The log4net internal debugging can be enabled by setting an <appSetting>
in the application's config file:

<appSettings>
  <add key="log4net.Internal.Debug" value="true"/>
</appSettings>

This must go into the applications .config file (or if it is a web app
then the Web.config file).


Setting the XmlConfigurator attribute on your assembly should cause it
to load its configuration separately from the main application.

There is an example application that is included in the log4net download
that shows this behaviour.

examples\net\1.0\Repository

This is made up of 3 assemblies.

SharedModule - this is an ordinary DLL, it uses logging, but does not
configure it.
SimpleApp - this is an EXE, it configures and uses logging.
SimpleModule - this is a DLL, that setups its own repository and
configures it.

To see the RepositoryAttribute and XmlConfiguratorAttribute have a look
at this example source file:

examples\net\1.0\Repository\SimpleModule\cs\src\Math.cs

Cheers,
Nicko
------------
Nicko Cadell
log4net development
http://logging.apache.org/log4net

-----Original Message-----
From: minherz [mailto:minherz@gmail.com] 
Sent: 01 May 2007 12:38
To: log4net-user@logging.apache.org
Subject: RE: 3rd party assembly logging configuration


The subject of using repository is little cloudy for me, even after
reading
documentation. If i want to have same hierarchical repository for my
library
but starting from different root, then i have to use Repository
attribute at
the assembly level of my library. Is it correct?
Do i have to enable internal debugging of log4net in both configuration
files or only in the application's configuration?
After i make use of different repository does the XmlConfigurer
attribute in
the assembly level of my library enough to force log4net loading
configuration from the different file?

Thank you.
-- 
View this message in context:
http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
.html#a10267809
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by minherz <mi...@gmail.com>.
The subject of using repository is little cloudy for me, even after reading
documentation. If i want to have same hierarchical repository for my library
but starting from different root, then i have to use Repository attribute at
the assembly level of my library. Is it correct?
Do i have to enable internal debugging of log4net in both configuration
files or only in the application's configuration?
After i make use of different repository does the XmlConfigurer attribute in
the assembly level of my library enough to force log4net loading
configuration from the different file?

Thank you.
-- 
View this message in context: http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813.html#a10267809
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: 3rd party assembly logging configuration

Posted by ni...@apache.org.
It sounds like you want to separate the logging done in your shared
assembly and the (optional) logging done in the main application.

All logging and logging configuration is done using a logger repository.
There is a default logger repository that is used by all assemblies,
however it is possible to use a different logger repository for your
shared assemblies.

On your shared assemblies you should specify the
log4net.Config.RepositoryAttribute. The RepositoryAttribute is used to
map the assembly to a named repository. All your shared assemblies
should specify the same name for the repository. E.g.

[assembly: log4net.Config.Repository("shared-assembly-product-name")]

Then all your assemblies will use a repository that is different to the
1 used by the application. This means that your assemblies will have
separate logging behaviour to the main application and the main
application does not need to know about log4net.

You should still use the XmlConfiguration attribute in your assembly to
specify where the logging configuration for your repository should be
loaded from.

This is quite complex to setup correctly. You may need to enable log4net
internal debug to see which logger repositories log4net is creating and
where it is trying to load the config from. For details see:

http://logging.apache.org/log4net/release/faq.html#internalDebug

Cheers,
Nicko

------------
Nicko Cadell
log4net development
http://logging.apache.org/log4net


-----Original Message-----
From: minherz [mailto:minherz@gmail.com] 
Sent: 30 April 2007 11:07
To: log4net-user@logging.apache.org
Subject: 3rd party assembly logging configuration


Hello. I failed finding a clear answer to my question here, though there
are
several posts that touching the subject.
I have a set of shared assembly which use log4net. However, the
application
does not have to use it as well i do not want that the log4net
configuration
of the application will dictate logging behavior of the shared assembly.
In
the case the developer wants to output log from the shared assembly he
will
have to define a separate configuration file. While the file is not
there no
logging should be performed by the shared assembly.
I tried defining XmlConfiguration attribute with explicit config file
name
in the AssemblyInfo of my shared library. It is either ignored or does
not
work for other reason. All the output is displayed according to root
configuration of the application.
I know that i can filter it out by using logger element, but i have
different requirement.
I found several articles that suggest using in code call for
configuration.
My problem is that the shared assembly is a class library which provide
a
collection of classes and i have no idea which of them will be created
first. I also can not define some initialization method as it is against
the
design requirements.
Can anybody advise how i can solve this matter?
-- 
View this message in context:
http://www.nabble.com/3rd-party-assembly-logging-configuration-tf3668813
.html#a10251023
Sent from the Log4net - Users mailing list archive at Nabble.com.