Log4net - getting applications specific to one logger only

I am looking for a way to connect all applications to one log instance.

I tried:

Hierarchy hierarchy = LogManager.GetRepository() as Hierarchy;
hierarchy.GetAppenders()

      

as per the documentation, this returns all apps for all currently configured logs.

When I try this:

LogManager.GetLogger("MyLoggerName").Logger.Repository.GetAppenders();

      

I am getting the same result.

I would like to get only prefixes attached to one logger ("MyLoggerName" in this case)

Where am I going wrong?

+3


source to share


1 answer


When you call the following code

LogManager.GetLogger("MyLoggerName").Logger.Repository.GetAppenders();

      

you are indeed asking for the same data as hierarchy.GetAppenders()

because Hierarchy

inherits LoggerRepositorySkeleton

, which implements ILoggerRepository

, the return type Logger.Repository

.



However, you can get a list of "first level" addins using a class Logger

that lives in a namespace Hierarchy

:

var h = LogManager.GetRepository() as Hierarchy;
var l = h.GetLogger("MyLoggerName", h.LoggerFactory);
// do something with the l.Appenders property

      

You will have to handle special cases like bufefring or filtering appenders

+3


source







All Articles