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.
This cannot be easily achieved. For example TypeMock uses the .NET framework profiler API to monitor an application's execution. It allows you to register for different events and be notified when a method is called, an exception occurs, ... but this is not going to be an easy task.
On the other hand you could use AOP but it requires you to modify your code so that the caller uses some generated proxy instead of the real class. Spring.NET has some nice features about it.
So basically without using the .NET framework Profiler API or without writing some custom code that reads those attributes from a given class using reflection you cannot achieve this. Attributes are just class metadata and without something that would make sense of them they do nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With