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
|
||||
}
|
||||
|
||||
public interface ILogger {
|
||||
public interface ILogger : ISingletonDependency {
|
||||
bool IsEnabled(LogLevel level);
|
||||
void Log(LogLevel level, Exception exception, string format, params object[] args);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user