首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过继承现成的(和有效的)自定义属性来实现Log4PostSharp项目

通过继承现成的(和有效的)自定义属性来实现Log4PostSharp项目
EN

Stack Overflow用户
提问于 2010-09-05 19:34:03
回答 1查看 145关注 0票数 0

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

代码语言:javascript
复制
  [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;
    }

    ...
  }

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

代码语言:javascript
复制
[LogWithException]
private void DoThrowException()
{
  throw new Exception("test exception");
}

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

代码语言:javascript
复制
> msbuild Log4PostSharp.Test.csproj /p:PostSharpBuild=Diag /p:PostSharpTrace="AssemblyBinding;Project" /v:detailed

解决这个问题的正确方法是什么?我尝试做的错误的事情是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-05 20:27:18

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3645910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档