[英]Error when compiling c# project in VS2012 when using Postsharp
I am currently working on a project where we were wanting to add PostSharp functionality. 我目前正在开发一个我们想要添加PostSharp功能的项目。
I have set up my Postsharp attribute as so 我已经设置了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);
}
}
and trying to use it as 并尝试将其用作
[NLogTrace(NLogLevel.Debug)]
However when compiling the project I am getting the following error: 但是在编译项目时,我收到以下错误:
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..
Any help would be appreciated 任何帮助,将不胜感激
[NonSerialized]
public Logger logger;
Declaring the logger as marked above has solved the problem I was having 声明上面标记的记录器已经解决了我遇到的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.