mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Medium Trust: Avoid the use of castle trace logger under medium trust.
--HG-- branch : dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user