diff --git a/src/LoggingExtension.cs b/src/LoggingExtension.cs index 98e5ce1..9c63e4a 100644 --- a/src/LoggingExtension.cs +++ b/src/LoggingExtension.cs @@ -1,12 +1,15 @@ using System; using Microsoft.Extensions.Logging; using System.Reflection; +using System.Runtime.CompilerServices; using Unity.Builder; using Unity.Extension; using Unity.Policy; +using System.Security; namespace Unity.Microsoft.Logging { + [SecuritySafeCritical] public class LoggingExtension : UnityContainerExtension { #region Fields @@ -54,29 +57,26 @@ namespace Unity.Microsoft.Logging #endregion - #region IBuildPlanPolicy - - - public void BuildUp(ref BuilderContext context) - { - context.Existing = null == context.DeclaringType - ? LoggerFactory.CreateLogger(context.Name ?? string.Empty) - : LoggerFactory.CreateLogger(context.DeclaringType); - context.BuildComplete = true; - } - - #endregion - - #region IResolveDelegateFactory public ResolveDelegate GetResolver(ref BuilderContext context) { return ((ref BuilderContext c) => { - return null == c.DeclaringType + Type declaringType = null; + + if (IntPtr.Zero != c.Parent) + { + unsafe + { + var parenContext = Unsafe.AsRef(c.Parent.ToPointer()); + declaringType = parenContext.RegistrationType; + } + } + + return null == declaringType ? LoggerFactory.CreateLogger(c.Name ?? string.Empty) - : LoggerFactory.CreateLogger(c.DeclaringType); + : LoggerFactory.CreateLogger(declaringType); }); } diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index cd31244..9d48ad7 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ using System; using System.Security; -//[assembly:CLSCompliant(true)] -//[assembly:SecurityTransparent] \ No newline at end of file +[assembly:CLSCompliant(true)] +[assembly: AllowPartiallyTrustedCallers] diff --git a/src/Unity.Microsoft.Logging.csproj b/src/Unity.Microsoft.Logging.csproj index 13ab79e..3a1e518 100644 --- a/src/Unity.Microsoft.Logging.csproj +++ b/src/Unity.Microsoft.Logging.csproj @@ -38,6 +38,11 @@ ..\..\Container\src\Unity.Container.csproj + + + true + +