I have been trying PostSharp AOP for a while. I am able to design simple aspects and use them fine. But I am trying to find the best way to achieve this scenario.
Scenario:
Log the method on entry and exit.
Log developer specified statements within the method.
Assume that I have built an Apsect(LogMethodAspect) that logs the method during entry an exit.
However, now I want to log a specific statement. I want this statement to be part of the same log.
Options:
- Create another aspect (LogStatementAspect) that will log the parameters, now call this method when I want to log a statement.
- Create an interface with one method called "LogThis" and in the assembly specify an aspect specifically for "LogThis" method.
I am trying to find an appropriate way such that it will require the least amount of dependency.
Can you create an aspect on a statement? Can you call an underlying Aspect method directly?
Any help would be great.
Sample pseudo code:
[LogMethodAspect]
Mothod1 (input1, input2)
{
Do Something
"Log this info" // How can I re-use the logging methodology already created in the aspect - LogMethodAspect
Do Something more
}