2010-09-05 110 views
0

需要從現成的(和工作)自定義屬性繼承修改Log4PostSharp項目。它看起來類似於這樣: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 

哪一種解決問題的正確方法是?我正在嘗試做什麼錯事?

回答

1

Log4PostSharp.Weaver.LogTask::ProvideAdvice()出現了下面一行:var customAttributeEnumerator = customAttributeDictionaryTask.GetAnnotationsOfType(typeof(LogAttribute), true);GetAnnotationsOfType()的第二個屬性是false,這意味着只應該發現LogAttribute註釋。它更改爲true造成LogAttribute所有後代(包括我LogWithExceptionAttribute)加以考慮。