mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Security;
|
||||||
|
using System.Security.Permissions;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Core;
|
using Autofac.Core;
|
||||||
using Castle.Core.Logging;
|
using Castle.Core.Logging;
|
||||||
@@ -14,11 +16,17 @@ namespace Orchard.Logging {
|
|||||||
// 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();
|
||||||
|
|
||||||
|
try {
|
||||||
// by default, use Castle's TraceSource based logger factory
|
// 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();
|
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
|
// 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) {
|
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) {
|
||||||
|
|||||||
Reference in New Issue
Block a user