[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4net-user
Subject:    RE: How to dynamically query and set logger levels?
From:       Joe <jocularjoe () hotmail ! com>
Date:       2013-12-04 21:17:30
Message-ID: DUB125-DS167F0DDB9FEB7F4B3C86B3C3D40 () phx ! gbl
[Download RAW message or body]

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!


[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" \
CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 \
(filtered medium)"><style><!-- /* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
code
	{mso-style-priority:99;
	font-family:"Courier New";}
pre
	{mso-style-priority:99;
	mso-style-link:"HTML Preformatted Char";
	margin:0cm;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-priority:99;
	mso-style-link:"HTML Preformatted";
	font-family:Consolas;
	mso-fareast-language:EN-GB;}
span.EmailStyle20
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";
	mso-fareast-language:EN-US;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link=blue vlink=purple><div \
class=WordSection1><p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I posted an \
answer to your SO question.<o:p></o:p></span></p><p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Basically \
the code sample you quoted isn&#8217;t accurate: instead of casting ILog to \
log4net.Repository.Hierarchy.Logger you should be casting ILog.Logger.&nbsp; \
<o:p></o:p></span></p><p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I&#8217;ve \
implemented an abstraction around these administrative functions: a class \
&#8220;LoggerTree&#8221; that exposes a hierarchy of instantiated loggers, with a \
method to update the Level for any node in the tree.<o:p></o:p></span></p><p \
class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I use this \
to display an administrative UI with a treeview of loggers with the option to change \
the logging level.<o:p></o:p></span></p><p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If \
anyone&#8217;s interested I&#8217;d be happy to share the \
code.<o:p></o:p></span></p><p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><b><span lang=EN-US \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span \
lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> George Mauer \
[mailto:gmauer@gmail.com] <br><b>Sent:</b> 04 December 2013 21:17<br><b>To:</b> \
log4net-user@logging.apache.org<br><b>Subject:</b> Re: How to dynamically query and \
set logger levels?<o:p></o:p></span></p><p \
class=MsoNormal><o:p>&nbsp;</o:p></p><div><div><p class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><a \
href="http://stackoverflow.com/questions/20384888/query-and-modify-log4net-logger-levels-from-code">I've \
posted this on Stackoverflow if anyone wants to answer it on there for SO \
rep..</a></span><o:p></o:p></p></div><div><p \
class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>I would like to create an \
area in my application that will let sysadmins modify logger levels \
directly.</span><o:p></o:p></p><div><p class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p></div><div><p \
class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><a \
href="http://stackoverflow.com/a/738239/5056" target="_blank">This stackoverflow \
answer from 2009</a>&nbsp;implies that I can do it \
with<o:p></o:p></span></p></div><div><p class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p></div><div><pre \
style='margin-bottom:7.5pt;line-height:13.5pt;background:#EEEEEE;vertical-align:baseline;white-space:pre-wrap;max-height:600px;word-wrap:normal;overflow:auto'><span \
style='font-size:10.5pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></pre><pre \
style='line-height:13.5pt;background:#EEEEEE;vertical-align:baseline'><code><span \
style='font-family:Consolas;color:darkblue;border:none windowtext \
1.0pt;padding:0cm'>foreach</span></code><code><span \
style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'> (<span \
style='color:#2B91AF'>ILog</span> logger <span style='color:darkblue'>in</span> \
log4net.<span style='color:#2B91AF'>LogManager</span>.<span \
style='color:#2B91AF'>GetCurrentLoggers</span>())<o:p></o:p></span></code></pre><pre \
style='line-height:13.5pt;background:#EEEEEE;vertical-align:baseline'><code><span \
style='font-family:Consolas;border:none windowtext \
1.0pt;padding:0cm'>{<o:p></o:p></span></code></pre><pre \
style='line-height:13.5pt;background:#EEEEEE;vertical-align:baseline'><code><span \
style='font-family:Consolas;border:none windowtext 1.0pt;padding:0cm'>&nbsp; \
((log4net.<span style='color:#2B91AF'>Repository</span>.<span \
style='color:#2B91AF'>Hierarchy</span>.<span \
style='color:#2B91AF'>Logger</span>)logger).<span style='color:#2B91AF'>Level</span> \
= <o:p></o:p></span></code></pre><pre \
style='line-height:13.5pt;background:#EEEEEE;vertical-align:baseline'><code><span \
style='font-family:Consolas;border:none windowtext \
1.0pt;padding:0cm'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log4net.<span \
style='color:#2B91AF'>Core</span>.<span style='color:#2B91AF'>Level</span>.<span \
style='color:#2B91AF'>Error</span>;<o:p></o:p></span></code></pre><pre \
style='line-height:13.5pt;background:#EEEEEE;vertical-align:baseline'><code><span \
style='font-family:Consolas;border:none windowtext \
1.0pt;padding:0cm'>}</span></code><span \
style='font-size:10.5pt;font-family:Consolas'><o:p></o:p></span></pre></div><div><p \
class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p></div><div><p \
class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>My \
application uses <a href="https://www.nuget.org/packages/log4net/">log4net 2.0.3 \
(1.2.13)</a> and this seems to not be available as no implementation of ILog inherits \
that class.&nbsp;<o:p></o:p></span></p></div><div><p class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p></div><div><p \
class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'>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.<o:p></o:p></span></p></div><div><p \
class=MsoNormal><span \
style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p></div><div><p \
class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>PS. \
How exactly does the email confirmation protect me from someone subscribing falsely? \
I subscribed by emailing from this \
address!<o:p></o:p></span></p></div></div></div></div></body></html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic