I achieve this through direct manipulation with .log4net.config file.
This sample for TraceAppender sets threshold for this appender to OFF
and in effect disables this appender.
public void SetAppenderThreshold(string appenderName, Level level)
{
XmlNode appenderNode = GetAppenderNode(appenderName);
Trace.Assert(appenderNode != null, "appenderNode != null");
XmlNode thresholdNode = appenderNode["threshold"];
if (thresholdNode == null)
{
thresholdNode =
appenderNode.AppendChild(_configXmlDoc.CreateElement("threshold"));
thresholdNode.Attributes.Append(_configXmlDoc.CreateAttribute("value"));
}
XmlNode attr = thresholdNode.Attributes["value"];
if (attr == null)
{
throw ExcUtils.XmlAttributeNotFound("value", thresholdNode);
}
attr.Value = level.Name;
}
public XmlNode GetAppenderNode(string appenderName)
{
string xPath =
string.Format("/configuration/log4net/[EMAIL PROTECTED]'{0}']", appenderName);
return
_configXmlDoc.DocumentElement.SelectSingleNode(xPath);
}
---------
Prostredi: C#, VS2005 Pro, XP Pro/P4 3GHz, 2GB RAM
___________________________________________________
Karel Kral, senior developer
ANETE, s.r.o.
___________________________________________________
Dne 24.12.2007 15:18, Erlis Vidal napsal(a):
> Hi all!
>
>
>
> My current configuration use an smtpAppender with a LevelRangerFilter
> setted in order to send ERROR messages, but in some cases I would like
> to disable the email capabilities, in order to achieve something similar
> to the previous discussion of “Elapsed time evaluator” but in my case I
> want to manage this in my code.
>
>
>
> Is there any idea for this?
>
> Thanks in advance and Merry Christmas to everybody.
>
>
>
> --Erlis
>