我想将VerboseTraceAspect
应用于我的解决方案,并将该属性应用于除
TestProject.Logging.*
和TestProject.Tracing.*
我正在使用以下示例,但它似乎不起作用。我做错了吗?如果是这样,应该怎么做?
谢谢你。
[assembly: VerboseTraceAspect(AspectPriority = 0, AttributeExclude = true, AttributeTargetTypes = "TestProject.Logging.*|TestProject.Tracing.*")]
[assembly: VerboseTraceAspect(AspectPriority = 1, AttributeExclude = true, AttributeTargetMembers = "regex:get_.*|set_.*")]
[assembly: VerboseTraceAspect(AspectPriority = 2, AttributeTargetTypes = "TestProject.*",
AttributeTargetTypeAttributes = MulticastAttributes.Public,
AttributeTargetMemberAttributes = MulticastAttributes.Public,
AttributeTargetElements = MulticastTargets.Method)]
答案 0 :(得分:2)
您需要更正从TestProject.Logging.*
和TestProject.Tracing.*
删除跟踪属性的第一行中的目标类型表达式。如果要指定使用管道分隔的多个选项,则应使用正则表达式语法。
您还需要使用AttributePriority
代替AspectPriority
属性。属性多播是在AspectPriority
产生任何影响之前执行的。稍后会用它来确定方面的执行顺序。
“exclude”属性必须具有更高的优先级值(在较低值之后处理较高的值)。
[assembly: VerboseTraceAspect(
AttributePriority = 1,
AttributeExclude = true,
AttributeTargetTypes = @"regex:TestProject\.Logging\..+|TestProject\.Tracing\..+")]
[assembly: VerboseTraceAspect(
AttributePriority = 2,
AttributeExclude = true,
AttributeTargetMembers = "regex:get_.*|set_.*")]
[assembly: VerboseTraceAspect(
AttributePriority = 0,
AttributeTargetTypes = "TestProject.*",
AttributeTargetTypeAttributes = MulticastAttributes.Public,
AttributeTargetMemberAttributes = MulticastAttributes.Public,
AttributeTargetElements = MulticastTargets.Method)]