tags:

views:

207

answers:

1

Hi,

This is what i intend to do:

  1. I want to write a Aspect oriented NLog specific onmethodexecutionaspect class.
  2. But i still want to ensure that the calling code is attributed using a general attribute class which will internally load the NLog or TraceX etc specific implementation of methodexecutionaspect depending on what is specified in the application configuration file.

What is the best way to approach this?

I am thinking of writing a abstract class which will derive from postsharp method execution aspect. Then i will have another dll which will have a NLog specific implementation... so it will have a class which will derive from the general method execution aspect class i have created in the general dll.

The consuming code will only reference the general class dll i have written, and that class will doa load of NLog specific dll i have written if that is what is specified in the application config.

makes sense?

+1  A: 

I think you are on the right track. However, try using OnMethodBoundaryAspect instead. It is faster at runtime than OnMethodInvocationAspect.

Try to take advantage of compile-time initialization (CompileTimeInitialize) and run-time initialization (RunTimeInitialize) and avoid doing anything costly in handlers.

Good luck.

-gael

Gael Fraiteur
Thanks Gael. Just need a bit more help on the approach i have in mind... where do you think i should put the code to do teh load of teh nlog specific things? Would it be in a static constructor of the general class (that dervis from OnMethodBoundaryAspect).I ask this because i want to make sure that the Nlog stuff is not loadede on every call to the class rediving from OnMethodBoundaryAspect, and only once per application that has classes decorated with my general class deriving from OnMethodBoundaryAspect.
You can use the static constructor, but be sure not to initialize your logging framework when PostSharp is running (see PostSharpEnvironment.IsPostSharpRunning).Use RuntimeInitialize when you want to initialize something that depends on the metadata (class name, method name) of the aspect target. For instance, if you need to initialize a trace category whose name is the name of the target type, RuntimeInitialize is the right location.-gael
Gael Fraiteur
Thnx. I will refer to that API and come back to you for any more clarifications.
A related question while i am at this work... can i use PostSharp along with "Common.Logging" library? Do you know of any helpful pointers on this.
I ask this because i want to make the best use of these two tools together - i.e. common.logging for providing me a common interface to logging with several loggers, and PostSharp for enabling me with aspects.
Yes, PostSharp is perfectly neutral to that choice.
Gael Fraiteur
Cool, thnx. Gael :-)