我想使用 AOP 为我的所有方法记录异常。我创建了一个与以下相同的属性:
[AttributeUsage(AttributeTargets.All)]
public class ClsLogger : System.Attribute
{
private string _exMsg;
public ClsLogger(string exMsg)
{
//
// TODO: Add constructor logic here
//
_exMsg = exMsg;
LogError();
}
public void LogError()
{
// This methods logs exception
// Log Exception
}
}
最后,我想使用此日志记录属性来记录我的应用程序方法的异常消息。我如何将异常消息传递给属性,因为它不是固定字符串而是可变的?有人可以帮忙吗?