mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
PERF: Fixing 16890 ILogger pooling
--HG-- branch : perf
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Orchard.Logging {
|
|||||||
Fatal
|
Fatal
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ILogger {
|
public interface ILogger : ISingletonDependency {
|
||||||
bool IsEnabled(LogLevel level);
|
bool IsEnabled(LogLevel level);
|
||||||
void Log(LogLevel level, Exception exception, string format, params object[] args);
|
void Log(LogLevel level, Exception exception, string format, params object[] args);
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,12 @@ using Module = Autofac.Module;
|
|||||||
namespace Orchard.Logging {
|
namespace Orchard.Logging {
|
||||||
|
|
||||||
public class LoggingModule : Module {
|
public class LoggingModule : Module {
|
||||||
|
private readonly IDictionary<string, ILogger> _loggerCache;
|
||||||
|
|
||||||
|
public LoggingModule() {
|
||||||
|
_loggerCache = new Dictionary<string, ILogger>();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Load(ContainerBuilder moduleBuilder) {
|
protected override void Load(ContainerBuilder moduleBuilder) {
|
||||||
// by default, use Orchard's logger that delegates to Castle's logger factory
|
// by default, use Orchard's logger that delegates to Castle's logger factory
|
||||||
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
|
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
|
||||||
@@ -65,8 +71,15 @@ namespace Orchard.Logging {
|
|||||||
var propertyInfo = entry.PropertyInfo;
|
var propertyInfo = entry.PropertyInfo;
|
||||||
|
|
||||||
yield return (ctx, instance) => {
|
yield return (ctx, instance) => {
|
||||||
var propertyValue = ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType));
|
string component = componentType.ToString();
|
||||||
propertyInfo.SetValue(instance, propertyValue, null);
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user