Log4PostSharp project by inheriting from the ready-made (and working) custom attribute
Need to modify Log4PostSharp project by inheriting from 开发者_如何学JAVAthe ready-made (and working) custom attribute. It looks similar to this:
[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;
}
...
}
This is how I've chosen to annotate some unit-test code:
[LogWithException]
private void DoThrowException()
{
throw new Exception("test exception");
}
Wanted to try to debug the compile-time process, tried to compile from the command line but couldn't get any hint:
> msbuild Log4PostSharp.Test.csproj /p:PostSharpBuild=Diag /p:PostSharpTrace="AssemblyBinding;Project" /v:detailed
Which is the right way to tackle the problem? What is the wrong thing I am trying to do?
In Log4PostSharp.Weaver.LogTask::ProvideAdvice()
there was a following line: var customAttributeEnumerator = customAttributeDictionaryTask.GetAnnotationsOfType(typeof(LogAttribute), true);
. The second attribute of GetAnnotationsOfType()
was false
, meaning that only LogAttribute
annotations should be discovered. Changing it to true
caused all the descendants of LogAttribute
(including my LogWithExceptionAttribute
) to be considered.
精彩评论