You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by Ron Grabowski <ro...@yahoo.com> on 2006/10/14 20:11:16 UTC
Set Logger's Level to its EffectiveLevel to avoid for() loop
I was brainstorming about ways to avoid the for() loop that is used to
lookup the EffectiveLevel to determine if a message should be sent to
the apppenders. I came up with this plugin that listens for when the
repository has been configured and sets the Level property of the
Logger to a known value instead of requiring the EffectiveLevel to be
calculated each time a message is processed. I haven't actually gotten
it to work yet but this may spark an idea for someone else:
public class LoggerLevelOptmizerPlugin : PluginSkeleton
{
public LoggerLevelOptmizerPlugin() :
base("LoggerLevelOptimizerPlugin")
{
// empty
}
public override void Attach(ILoggerRepository repository)
{
base.Attach(repository);
repository.ConfigurationChanged +=
new LoggerRepositoryConfigurationChangedEventHandler(
repository_ConfigurationChanged);
}
private void repository_ConfigurationChanged(object sender, EventArgs
e)
{
foreach (ILogger logger in LoggerRepository.GetCurrentLoggers())
{
Logger hierarchyLogger = logger as Logger;
if (hierarchyLogger != null)
{
hierarchyLogger.Level = hierarchyLogger.EffectiveLevel;
}
}
}
}
I noticed that the logger's Level isn't checked before its
EffectiveLevel. Shouldn't this code:
return level >= this.EffectiveLevel;
be changed to this:
if (m_level != null)
{
return level >= m_level;
}
else
{
return level >= this.EffectiveLevel;
}
in log4net.Repository.Hierarchy.Logger?
I'll keep hacking at it...