需要通过继承现成(和工作)的自定义属性来修改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解决这个问题的正确方法是什么?我尝试做的错误的事情是什么?
发布于 2010-09-05 20:27:18
在Log4PostSharp.Weaver.LogTask::ProvideAdvice()中有一行代码:var customAttributeEnumerator = customAttributeDictionaryTask.GetAnnotationsOfType(typeof(LogAttribute), true);。GetAnnotationsOfType()的第二个属性是false,这意味着应该只发现LogAttribute注释。将其更改为true会导致考虑LogAttribute的所有后代(包括我的LogWithExceptionAttribute)。
https://stackoverflow.com/questions/3645910
复制相似问题