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 George Mauer <gm...@gmail.com> on 2013/12/04 21:16:54 UTC

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!

RE: How to dynamically query and set logger levels?

Posted by Joe <jo...@hotmail.com>.
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:gmauer@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!


Subscription Process (was Re: How to dynamically query and set logger levels?)

Posted by Stefan Bodewig <bo...@apache.org>.
Since your original question as already been answered, let me answer
your sidenote :-)

On 2013-12-04, George Mauer wrote:

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

I protects you from being subscribed when you never asked for it.  For
one it is easy to fake the sender when sending the subscription
request.  Also you can send a request to subscribe a different email
address by sending to list-subscribe-foo=example.org@host.  Thew
confirmation step ensures you can actually read messages sent to the
subscribed address and you really want to be subscribed - and are not
victim of somebody trying to fill your mailbox.

Stefan