C# 使用EntLib策略注入块进行日志记录+;结构图+;log4net

C# 使用EntLib策略注入块进行日志记录+;结构图+;log4net,c#,asp.net-mvc,enterprise-library,aop,structuremap,C#,Asp.net Mvc,Enterprise Library,Aop,Structuremap,我正在尝试使用:在ASP.NET MVC应用程序中通过AOP添加日志记录 企业库策略注入应用程序块 结构图 log4net 这就是我所拥有的: web.config <configSections> <section name="policyInjection" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Mi

我正在尝试使用:
在ASP.NET MVC应用程序中通过AOP添加日志记录

  • 企业库策略注入应用程序块
  • 结构图
  • log4net
这就是我所拥有的:

web.config

  <configSections>
    <section name="policyInjection" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.PolicyInjectionSettings, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>   

  <policyInjection>
    <policies>
      <add name="Policy">
        <matchingRules>
          <add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TagAttributeMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            match="Log" name="Tag Attribute Matching Rule" />
        </matchingRules>
        <handlers>
          <add type="MyApp.Website.MyLoggingCallHandler, MyApp.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            name="Custom Handler" />
        </handlers>
      </add>
    </policies>
  </policyInjection>
StructureMapControllerFactory:

public class StructureMapControllerFactory : DefaultControllerFactory
{
  protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
  {
    var instance = ObjectFactory.GetInstance(controllerType);
    return PolicyInjection.Wrap<IController>(instance);
  }
}
MyLoggingCallHandler:

namespace MyApp.Website
{
    [ConfigurationElementType(typeof(CustomCallHandlerData))]
    public class MyLoggingCallHandler : ICallHandler
    {
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
          //Implementation
        }

        public int Order { get; set; }
    }
}
问题是:调用处理程序永远不会被触发

我做错了什么?

可以在这里找到答案:

[Tag("Log")]
public class HomeController : Controller
{
  //Implementation
}
namespace MyApp.Website
{
    [ConfigurationElementType(typeof(CustomCallHandlerData))]
    public class MyLoggingCallHandler : ICallHandler
    {
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
          //Implementation
        }

        public int Order { get; set; }
    }
}