Denis,
> I may asking a few of these over the next week but the first
> one that I have is on the loggerRepository.
The logger repository organises the loggers. Each logger has a name and can
be retrieved by name from the repository. It is up to the repository
implementation to define how the loggers are organised. Currently there is
only one implementation of the ILoggerRepository interface and that is the
Hierarchy. This is the repository that organises its loggers into a
hierarchy based on the dots in the names, E.g.:
Logger "foo" is the parent of logger "foo.bar". The child logger will
inherit the settings of the parent unless they are overridden. This is all a
function of the Hierarchy implementation and is not intrinsic to the
ILoggerRepository or ILogger interfaces.
This is designed to allow more than type of organisation of loggers in case
anyone thinks up a better way of doing it.
> The embolden part is what I am most confused about. How
> would it be that applications that use my components not be
> aware of log4net. They would still need to have log4net in
> their bin folder if the assembly is not installed in the GAC right?
Within a repository the loggers exist within a flat namespace.
Imagine I write a component that uses a logger called "database" and write a
lot of Warn messages to it.
Your application uses this component.
If you want to use the logger called "database" you will find that any
messages you write are swamped by messages from my component.
This is because there is no separation between the components within the
repository.
Further more, if you decide that you don't want ignore all log messages from
my component how can you configure log4net to do this? You need to know all
the names of the loggers that I might have used in my component. This might
be non trivial to discover.
This can all be solved by using a separate name space for our logger names,
then it is clear which loggers belong to which component. In log4net this is
achieved by having multiple logger repository instances. These separate
repositories can then be configured independently.
This also means that if I write my component to use and configure a separate
logger repository then an application that uses my component but does not
use log4net for logging does not have to configure log4net. It still
requires the log4net.dll as it is a prerequisite of my component, but the
app does not have to understand how to configure log4net.
> Also, I was wondering if anyone out there has found a way to
> implement log4net without having to declare a static logger
> in each class. Kind of like just having a static class that
> you could call from any class and maybe pass in the name of
> the logger each time you used it. I am trying to
> conceptualize a way to use log4net without having to have
> developers know what it takes to implement it on each page.
Well you can just lookup the logger each time:
LogManager.GetLogger(name).Info("hello world");
You can wrap this up in a static method of your own if you prefer:
public class Log
{
public static void Info(string logger, string msg)
{
LogManager.GetLogger(logger).Info(msg);
}
}
However the LogManager.GetLogger() code path is not optimised which is why
we recommend caching the value.
Cheers,
Nicko
------------
Nicko Cadell
log4net dev