Reputation: 5063
I have just started using Postsharp as a way to do logging etc. on a project and have come across an issue I have yet to resolve.
In my project I have created my LogAttribute which correctly is logging out the information that I am trying to do e.g. Parameters going in and out methods. The only issue is that it is also doing this for all constructors as well, which I am not wanting to be logged.
Is there a way of excluding constructors from being logged out?
My GlobalAspects.cs looks similar to:
using PostSharp.Patterns.Diagnostics;
using PostSharp.Extensibility;
[assembly: TraceAttribute(AttributeTargetTypes = "myNamespace.toLog.*", AttributeTargetTypeAttributes = MulticastAttributes.Public, AttributeTargetMemberAttributes = MulticastAttributes.Public)]
My OnEntry, OnSuccess and On Exception methods in my attribute are all variants on:
StringBuilder output = new StringBuilder();
output.Append("Entering: ");
output.Append(this.methodName);
for (int i = 0; i < args.Arguments.Count; i++)
{
output.Append(" Argument: " + i + " - ");
output.Append(args.Arguments.GetArgument(i) ?? "null");
}
m_logger.Trace(output);
Upvotes: 1
Views: 953
Reputation: 5063
By adding the following to the attribute declaration it seems to have resolved the issue:
[MulticastAttributeUsage(MulticastTargets.Method, TargetMemberAttributes = MulticastAttributes.Instance)]
[Serializable]
public class TraceAttribute : OnMethodBoundaryAspect
{
}
Upvotes: 5