Jeff
Jeff

Reputation: 397

PostSharp Multicast not working in Outlook plugin code

I am using PostSharp in an Outlook Plugin app. If I add the following attribute to a class in my project it logs properly:

namespace Foo.Bar
{
[Log(AttributeTargetMemberAttributes = MulticastAttributes.Public)]
public class FooBar {...}
}

What I really want to do is log everything in the Foo.* namespace. I tried using the addin in VS which created a globalaspects.cs and updated my project.pssln file. At this point it wont build with the following error msg:

.dll uses non-licensed features (PostSharp Professional). Please enter a valid license key.

I figured it was recursing on itself so I added an AttributeExclude = true in the assembly line that was generated for me. It now looks like this (in globalaspects.cs):

[assembly: Log(AttributeExclude = true, AttributeTargetTypes = "Foo.*", AttributeTargetTypeAttributes = MulticastAttributes.Public, AttributeTargetMemberAttributes = MulticastAttributes.Public)]

No luck, it doesn't log anything this way. Any ideas why?

Additional info: I am logging to log4net and I have other logging code that is working (it also works at both the class and method levels with PostSharp).

Upvotes: 1

Views: 161

Answers (1)

Daniel Balas
Daniel Balas

Reputation: 1850

According to this page free license of PostSharp currently has limitation on number of methods on which [Log] attribute is applied. In my opinion, you have exceeded this number by applying the aspect on the whole namespace.

AttributeExclude means that the attribute will not be applied on declarations that satisfy conditions set in this attribute. It is basically set inclusion/exclusion operation. For example you can include Namespace1, exclude Namespace1.Namespace2 and again include Namespace1.Namespace2.Namespace3.

Therefore the following would be correct:

[assembly: Log(AttributeTargetTypes = "Foo.*",
               AttributeTargetTypeAttributes = MulticastAttributes.Public, 
               AttributeTargetMemberAttributes = MulticastAttributes.Public)]

For more information about attribute multicasting, you can take a look on this article.

Note to reviewers: I'm one of developers working on PostSharp. I'm aware that this answer touches licensing, which is behind the red line and I have tried my best not to cross it too much.

Upvotes: 0

Related Questions