【问题标题】:Log4PostSharp project by inheriting from the ready-made (and working) custom attributeLog4PostSharp 项目通过继承现成的(和工作的)自定义属性
【发布时间】:2010-09-05 11:34:03
【问题描述】:

需要通过从现成的(和工作的)自定义属性继承来修改 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

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

【问题讨论】:

    标签: .net c#-4.0 aop postsharp log4postsharp


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-25
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 2019-01-02
      • 1970-01-01
      相关资源
      最近更新 更多