This is my code of the Attribute Class that extends IMethodDecorator Interface
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Field)]
public class LogAttribute : Attribute, IMethodDecorator
{
ILogger log = Logger.Factory.GetLogger<Logger>();
String methodName;
public LogAttribute() {
}
public void Init(object instance, MethodBase method, object[] args)
{
methodName = method.Name;
}
public void OnEntry()
{
Console.WriteLine(methodName);
log.Debug(methodName);
}
public void OnExit()
{
Console.WriteLine("Exiting Method");
}
public void OnException(Exception exception)
{
Console.WriteLine("Exception was thrown");
}
}
I want to be able to use this as
[log("some logmessage")]
void method()
{
// some code
}
Any ideas ? I am using Method Decorator Fody package.