From 44b45a05f96a0e68b15ed15bde575cbe73c54193 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Wed, 3 Nov 2010 14:19:57 -0700 Subject: [PATCH] Medium Trust: Avoid the use of castle trace logger under medium trust. --HG-- branch : dev --- src/Orchard/Logging/LoggingModule.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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