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 Nicko Cadell <ni...@neoworks.com> on 2004/03/01 12:38:47 UTC

RE: Logger Repository?

Rich,

> If the loggers are hierarchical and my component and all the 
> loggers are in a defined namespace, could't I just set the 
> <logger> tag to a higher name.
> Like com.foo to handle com.foo.component1, com.foo.database 
> etc? (this is not me trying to find a way around using a 
> custom repository just wanting to make sure I understand the 
> capabilities of log4net).

This is absolutely what you should do. All I was saying is that it is not
possible to force all the loggers from a component to exist under a known
root. E.g. If a component uses loggers like "com.foo.component1" it is easy
to set the configuration on the "com.foo" logger, but the component could
also use loggers like "some-other-logger".


> Ok so now I am sold on using named repositories.  What do I 
> do next.  Again from the repositories section I gather that I 
> need to add a repository attribute into the assebly that I 
> want to have use the repository.  I assume I can just add 
> this to the assembly info class? Or does it have to be in a 
> particular spot in my assembly.  After that when I call 
> getLogger, is there something special that I have to do or is 
> it that transparent?  Also you mentioned that the repository 
> does not need to use the app config file, but can it?  

Using multiple repositories does make things more complicated. For example
the dom configurator cannot load multiple configurations from the same file,
therefore unless you want to configure all the repositories the same you
will need multiple config files.

To specify the name for a repository in an assembly you need to use the
log4net.Config.DomainAttribute e.g.:

[assembly: log4net.Config.Domain("my repository name")]

You can configure this repository using a DOMConfigurator attribute on the
same assembly e.g.:

[assembly: log4net.Config.DOMConfigurator(ConfigFile="my repository config
file")]

Having said this, if you have control over the components that make up your
application then it is simpler to use a single repository to manage your
logging.

Nicko