using C# Custom Attributes for exception and audit trail logging

is it possible to create a custom feature that captures exceptions made in a method that are set by a custom attribute?

im planning to do something like this:

[Logging(FeatureEnum.SomeFeature, IntentEnum.SomeIntent, "some comment")]
public void SomeMethodThatDoesATask()
{
    try
    {
      var doSomeAction = new LazyProcess();
      doSomeAction.WhoDunnit();
    }
    catch(Exception ex)
    {
       StaticMethodThatDoesLogging.CatchError(ex);
    }
}

Question is: How do I capture the Method name where this attribute was placed and what event was thrown? It can either capture an exception or just automatically log that this method was called.

8
задан Martin Ongtangco 23 December 2010 в 07:45
поделиться