I posted an answer to your SO question.

 

Basically the code sample you quoted isn't accurate: instead of casting ILog
to log4net.Repository.Hierarchy.Logger you should be casting ILog.Logger.  

 

I've implemented an abstraction around these administrative functions: a
class "LoggerTree" that exposes a hierarchy of instantiated loggers, with a
method to update the Level for any node in the tree.

I use this to display an administrative UI with a treeview of loggers with
the option to change the logging level.

 

If anyone's interested I'd be happy to share the code.

 

From: George Mauer [mailto:gma...@gmail.com] 
Sent: 04 December 2013 21:17
To: log4net-user@logging.apache.org
Subject: Re: How to dynamically query and set logger levels?

 

I've posted this on Stackoverflow if anyone wants to answer it on there for
SO rep..
<http://stackoverflow.com/questions/20384888/query-and-modify-log4net-logger
-levels-from-code> 

 

I would like to create an area in my application that will let sysadmins
modify logger levels directly.

 

This stackoverflow answer from 2009 <http://stackoverflow.com/a/738239/5056>
implies that I can do it with

 

 
foreach (ILog logger in log4net.LogManager.GetCurrentLoggers())
{
  ((log4net.Repository.Hierarchy.Logger)logger).Level = 
      log4net.Core.Level.Error;
}

 

My application uses log4net 2.0.3 (1.2.13)
<https://www.nuget.org/packages/log4net/>  and this seems to not be
available as no implementation of ILog inherits that class. 

 

Instead I can grab each ILog's instances of ILogger to give me the name but
will not let me query or set the Level. There is nothing I can cast this to
in the meantime as it seems to be implemented by an internal class.

 

PS. How exactly does the email confirmation protect me from someone
subscribing falsely? I subscribed by emailing from this address!

Reply via email to