0

需要通过从现成的(和工作的)自定义属性继承来修改 Log4PostSharp 项目。它看起来类似于:

  [AttributeUsage(
    AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Struct,
    AllowMultiple = true,
    Inherited = false)]
  [MulticastAttributeUsage(
  MulticastTargets.InstanceConstructor | MulticastTargets.StaticConstructor | MulticastTargets.Method,
    AllowMultiple = true)]
#if SILVERLIGHT
  [RequirePostSharp("Log4PostSharp", "Log4PostSharp.Weaver.SilverlightLogTask")]
#else
  [RequirePostSharp("Log4PostSharp", "Log4PostSharp.Weaver.LogTask")]
  [Serializable]
#endif
  public sealed class LogWithExceptionAttribute : LogAttribute
  {
    public LogWithExceptionAttribute()
    {
      ExceptionLevel = LogLevel.Error;
    }

    ...
  }

这就是我选择注释一些单元测试代码的方式:

[LogWithException]
private void DoThrowException()
{
  throw new Exception("test exception");
}

想尝试调试编译时进程,尝试从命令行编译但无法得到任何提示:

> msbuild Log4PostSharp.Test.csproj /p:PostSharpBuild=Diag /p:PostSharpTrace="AssemblyBinding;Project" /v:detailed

哪个是解决问题的正确方法?我想做的错事是什么?

4

1 回答 1

1

里面有Log4PostSharp.Weaver.LogTask::ProvideAdvice()以下一行:var customAttributeEnumerator = customAttributeDictionaryTask.GetAnnotationsOfType(typeof(LogAttribute), true);. GetAnnotationsOfType()was的第二个属性false,意味着只LogAttribute应该发现注释。将其更改为true导致LogAttribute(包括 my LogWithExceptionAttribute)的所有后代都被考虑。

于 2010-09-05T12:27:18.030 回答