From a4b1f2f36dee8a2164de47f2a7ae4646f77f6854 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Wed, 1 Dec 2010 15:46:13 -0800 Subject: [PATCH] PERF: Fixing 16890 ILogger pooling --HG-- branch : perf --- src/Orchard/Logging/ILogger.cs | 2 +- src/Orchard/Logging/LoggingModule.cs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Orchard/Logging/ILogger.cs b/src/Orchard/Logging/ILogger.cs index 045db2ef8..6e7963609 100644 --- a/src/Orchard/Logging/ILogger.cs +++ b/src/Orchard/Logging/ILogger.cs @@ -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); } diff --git a/src/Orchard/Logging/LoggingModule.cs b/src/Orchard/Logging/LoggingModule.cs index 9474c5671..de55b5017 100644 --- a/src/Orchard/Logging/LoggingModule.cs +++ b/src/Orchard/Logging/LoggingModule.cs @@ -11,6 +11,12 @@ using Module = Autofac.Module; namespace Orchard.Logging { public class LoggingModule : Module { + private readonly IDictionary _loggerCache; + + public LoggingModule() { + _loggerCache = new Dictionary(); + } + protected override void Load(ContainerBuilder moduleBuilder) { // by default, use Orchard's logger that delegates to Castle's logger factory moduleBuilder.RegisterType().As().InstancePerLifetimeScope(); @@ -65,8 +71,15 @@ namespace Orchard.Logging { var propertyInfo = entry.PropertyInfo; yield return (ctx, instance) => { - var propertyValue = ctx.Resolve(new TypedParameter(typeof(Type), componentType)); - propertyInfo.SetValue(instance, propertyValue, null); + string component = componentType.ToString(); + if (_loggerCache.ContainsKey(component)) { + propertyInfo.SetValue(instance, _loggerCache[component], null); + } + else { + var propertyValue = ctx.Resolve(new TypedParameter(typeof(Type), componentType)); + _loggerCache.Add(component, propertyValue); + propertyInfo.SetValue(instance, propertyValue, null); + } }; } }