use an aspect that inherits from the OnMethodBoundaryAspect and in the OnMethodEntry/OnMethodExit just make a call from your aspect to Unity to resolve your logger then do you logging.
Apply the aspect anyway you want (class, method or even assembly level)
[Serializable]
[MulticastAttributeUsage(MulticastTargets.Method, Inheritance=MulticastInheritance.Strict)]
public class LogAspect : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs args)
{
var Logger = Unity.Resolve<T>();
Logger.Write(args.Method.Name + " enter");
}
public override void OnExit(MethodExecutionArgs args)
{
var Logger = Unity.Resolve<T>();
Logger.Write(args.Method.Name + " exit");
}
}
To get your unity container I would use a service locator pattern.
public class iocServiceLocator
{
private static readonly IUnityContainer _container;
static iocServiceLocator()
{
_container = new UnityContainer();
}
public static void Initialize()
{
InitializeBootStrap();
}
private static void InitializeBootStrap()
{
//Register types here
}
public static T Get<T>()
{
return _container.Resolve<T>();
}
public static T Get<T>(string key)
{
return _container.Resolve<T>(key);
}
}