我目前正在开发一个我们想要添加 PostSharp 功能的项目。
我已经设置了我的 Postsharp 属性
[Serializable]
public class NLogTraceAttribute : OnMethodBoundaryAspect
{
private readonly string _logLevel;
ILogger logger;
public NLogTraceAttribute(string logLevel)
{
_logLevel = logLevel;
logger = new Logger("TraceAttribute");
}
public override void OnEntry(MethodExecutionArgs args)
{
LogAction("Enter", args);
}
public override void OnExit(MethodExecutionArgs args)
{
LogAction("Leave", args);
}
private void LogAction(string action, MethodExecutionArgs args)
{
var argumentsInfo = args.GetArgumentsInfo();
logger.Log(_logLevel, "{0}: {1}.{2}{3}", action, args.Method.DeclaringType.Name, args.Method.Name, argumentsInfo);
}
}
并尝试将其用作
[NLogTrace(NLogLevel.Debug)]
但是,在编译项目时,我收到以下错误:
Error 26 Cannot serialize the aspects: Type 'NLog.Logger' in Assembly
'NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'
is not marked as serializable..
任何帮助,将不胜感激