I think if we were going to optimise the EffectiveLevel by pushing the level changes down the hierarchy we would want to build this into the framework rather than leaving it to a plugin.
I guess a Logger would need to listen for an EffectiveLevelChanged event on its parent logger. When the parent's effective level is changed the child logger is notified, updates its effective level and raises the event for its children to update themselves in the same way. I think we need to keep EffectiveLevel separate from Level (i.e. what the user configured the logger with). I think that we would need to do some performance analysis to see if the EffectiveLevel loop is an issue or not. Any changes we make run the risk of making the code more complex or brittle so we need to take care that there is an overall benefit. On the subject of .net performance, this is a really good blog http://blogs.msdn.com/ricom/default.aspx Cheers, Nicko > -----Original Message----- > From: Ron Grabowski [mailto:[EMAIL PROTECTED] > Sent: 14 October 2006 19:11 > To: log4net-dev@logging.apache.org > Subject: 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... >