我正在探索一些 AOP,似乎使用 .NET PostSharp 是要走的路。
发生异常时,我想对数据库进行一些简单的日志记录。但是,我发现很难找到任何超越基础的使用 PostSharp 的真实可靠示例。我尝试了以下方法:
[Serializable]
public sealed class LogExceptionAttribute : ExceptionHandlerAspect
{
public override void OnException(MethodExecutionEventArgs eventArgs)
{
//do some logging here
}
}
然后将[LogException]
属性附加到方法
但我得到一个编译错误:
Error 7 The type "CoDrivrBeta1.Classes.LogExceptionAttribute" or one of its ancestor should be decorated by an instance of MulticastAttributeUsageAttribute. C:\work\CoDrivrBeta1\CoDrivrBeta1\EXEC CoDrivrBeta1
我不得不承认我对此很陌生,但这似乎是一个有趣的概念,我认为我只需要指出正确的方向