views:

655

answers:

1

Hi!

I want to log all calls to all class methods with a specific attribute. How would i do this?

This is what I have so far:

class ExecutionLogAttribute : Attribute
{
}

public class Human
{
    private Int32 age;

    [ExecutionLog]
    public void HaveBirthday()
    {
        age++;
    }
}

What would now be the best way to log all calls to HaveBirthday?

+8  A: 

Simple answer: PostSharp. More complex one: Spring.NET or custom AOP (this is what you need: Aspect-Oriented Programming) implementation using ContextBoundObject.

Anton Gogolev
Thanks for the response. I'm going to look in to that!
alexn