Это мой код класса атрибутов, который расширяет интерфейс IMethodDecorator.
[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");
}
}
Я хочу иметь возможность использовать это как
[log("some logmessage")]
void method()
{
// some code
}
Любые идеи ? Я использую пакет Method Decorator Fody.
public LogAttribute(string logMessage) { }
? - person jlvaquero   schedule 30.05.2016