Medium Trust: Avoid the use of castle trace logger under medium trust.

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2010-11-03 14:19:57 -07:00
parent 4486b13956
commit 44b45a05f9

View File

@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using Autofac;
using Autofac.Core;
using Castle.Core.Logging;
@@ -14,11 +16,17 @@ namespace Orchard.Logging {
// by default, use Orchard's logger that delegates to Castle's logger factory
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
// by default, use Castle's TraceSource based logger factory
moduleBuilder.RegisterType<TraceLoggerFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
try {
// by default, use Castle's TraceSource based logger factory
new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy).Demand();
moduleBuilder.RegisterType<TraceLoggerFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
} catch (SecurityException) {
// if security model does not allow it, fall back to null logger factory
moduleBuilder.RegisterType<NullLogFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
}
// call CreateLogger in response to the request for an ILogger implementation
moduleBuilder.Register((ctx, ps) => CreateLogger(ctx, ps)).As<ILogger>().InstancePerDependency();
moduleBuilder.Register(CreateLogger).As<ILogger>().InstancePerDependency();
}
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) {
@@ -70,4 +78,4 @@ namespace Orchard.Logging {
return loggerFactory.CreateLogger(containingType);
}
}
}
}