PERF: Fixing 16890 ILogger pooling

--HG--
branch : perf
This commit is contained in:
Suha Can
2010-12-01 15:46:13 -08:00
parent 2a0c34bcab
commit a4b1f2f36d
2 changed files with 16 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ namespace Orchard.Logging {
Fatal
}
public interface ILogger {
public interface ILogger : ISingletonDependency {
bool IsEnabled(LogLevel level);
void Log(LogLevel level, Exception exception, string format, params object[] args);
}

View File

@@ -11,6 +11,12 @@ using Module = Autofac.Module;
namespace Orchard.Logging {
public class LoggingModule : Module {
private readonly IDictionary<string, ILogger> _loggerCache;
public LoggingModule() {
_loggerCache = new Dictionary<string, ILogger>();
}
protected override void Load(ContainerBuilder moduleBuilder) {
// by default, use Orchard's logger that delegates to Castle's logger factory
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
@@ -65,8 +71,15 @@ namespace Orchard.Logging {
var propertyInfo = entry.PropertyInfo;
yield return (ctx, instance) => {
string component = componentType.ToString();
if (_loggerCache.ContainsKey(component)) {
propertyInfo.SetValue(instance, _loggerCache[component], null);
}
else {
var propertyValue = ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType));
_loggerCache.Add(component, propertyValue);
propertyInfo.SetValue(instance, propertyValue, null);
}
};
}
}