Asp.net mvc Spring.NET AOP日志记录可选参数问题

Asp.net mvc Spring.NET AOP日志记录可选参数问题,asp.net-mvc,spring-aop,spring.net,Asp.net Mvc,Spring Aop,Spring.net,我正在使用这个SO-answer:and-source-based中描述的设置来获取控制器的AOP日志记录 除了在没有可选参数的情况下调用带有可选参数的控制器方法外,所有这些都很好 我的测试方法: using System.Web.Mvc; public class OrderController : Controller { [SetMethodInfoAsMessage] virtual public ActionResult Test1() { retur

我正在使用这个SO-answer:and-source-based中描述的设置来获取控制器的AOP日志记录

除了在没有可选参数的情况下调用带有可选参数的控制器方法外,所有这些都很好

我的测试方法:

using System.Web.Mvc;

public class OrderController : Controller
{
   [SetMethodInfoAsMessage]
   virtual public ActionResult Test1()
   {
       return null;
   }

    [SetMethodInfoAsMessage]
    virtual public ActionResult Test2(int someParam = 0)
    {
        return null;
    }

    [SetMethodInfoAsMessage]
    virtual public ActionResult Test3(int? someParam = 0)
    {
        return null;
    }

    [SetMethodInfoAsMessage]
    virtual public ActionResult Test4(int someParam)
    {
        return null;
    }
}
以下是从浏览器获取这些方法时的相应行为:

http://localhost:62376/Order/Test1 -200行

http://localhost:62376/Order/Test2 -500内部服务器错误。“/”应用程序中出现服务器错误。参数字典包含“InheritanceAopProxy_7b93ae81d25d46529bebc7ed00ebc409”中方法“System.Web.Mvc.ActionResult Test2Int32”的参数“someParam”的无效条目。字典包含类型为“System.Reflection.Missing”的值,但参数需要类型为“System.Int32”的值。参数名称:参数

http://localhost:62376/Order/Test2?someParam=15 -200行

http://localhost:62376/Order/Test3 -500内部服务器错误。“/”应用程序中出现服务器错误。参数字典包含“InheritanceAopProxy_7b93ae81d25d46529bebc7ed00ebc409”中方法“System.Web.Mvc.ActionResult Test3System.Nullable1[System.Int32]”的参数“someParam”的无效条目。字典包含类型为“System.Reflection.Missing”的值,但该参数需要类型为“System.Nullable1[System.Int32]”的值。参数名称:参数

http://localhost:62376/Order/Test3?someParam=15 -200行

http://localhost:62376/Order/Test4 -500内部服务器错误。“/”应用程序中出现服务器错误。参数字典包含“InheritanceAopProxy_7b93ae81d25d46529bebc7ed00ebc409”中方法“System.Web.Mvc.ActionResult Test4Int32”的不可为空类型“System.Int32”的参数“someParam”的空项。可选参数必须是引用类型、可为null的类型或声明为可选参数。参数名称:参数

最后一次测试6。有意义,因为someParam是必需的。但是我们可以从第2页看到。四,。不提供可选参数将导致500。另一件需要注意的是4中的错误文本可选参数必须是引用类型、可为null的类型或声明为可选参数。所以根据这个,4。应该有用吧?因为Test3的可选参数可以为null

还有其他人经历过吗?除了手动向方法中添加日志语句之外,还有人对解决方法有什么建议吗

这是使用Spring.aop1.3.2,Spring.core1.3.2,Spring.Web。1.3.2和Spring.Web.Mvc3 1.3.2

编辑:根据要求,以下是建议。它只是注销参数,但不希望记录密码:

public class SetMethodInfoAsMessageAdvice : IMethodBeforeAdvice //, IThrowsAdvice
{
    private static readonly PELogger log = Log4NetHelper.GetLogger(typeof(SetMethodInfoAsMessageAdvice));

    public void Before(MethodInfo m, object[] args, object target)
    {
        ILog logger = LogManager.GetLogger(m.DeclaringType);

        string dump = args.ToJson();
        if (dump.Contains("password", StringComparison.OrdinalIgnoreCase))
            dump = "<password hidden>";

        logger.Info(m.Name + "(" + dump + ")");
   }
}

我们可以查看SetMethodInfoAsMessage属性的建议吗?这闻起来像是来自于那个或者Spring的代理。