diff --git a/src/Orchard/Logging/LoggingModule.cs b/src/Orchard/Logging/LoggingModule.cs index 5674b6fe2..b67da4b9c 100644 --- a/src/Orchard/Logging/LoggingModule.cs +++ b/src/Orchard/Logging/LoggingModule.cs @@ -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().As().InstancePerLifetimeScope(); - // by default, use Castle's TraceSource based logger factory - moduleBuilder.RegisterType().As().InstancePerLifetimeScope(); + try { + // by default, use Castle's TraceSource based logger factory + new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy).Demand(); + moduleBuilder.RegisterType().As().InstancePerLifetimeScope(); + } catch (SecurityException) { + // if security model does not allow it, fall back to null logger factory + moduleBuilder.RegisterType().As().InstancePerLifetimeScope(); + } // call CreateLogger in response to the request for an ILogger implementation - moduleBuilder.Register((ctx, ps) => CreateLogger(ctx, ps)).As().InstancePerDependency(); + moduleBuilder.Register(CreateLogger).As().InstancePerDependency(); } protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) { @@ -70,4 +78,4 @@ namespace Orchard.Logging { return loggerFactory.CreateLogger(containingType); } } -} +} \ No newline at end of file