我目前正在開發一個項目,我們希望添加PostSharp功能。使用Postharp編譯VS2012中的c#項目時出現錯誤
我已經建立了我的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..
任何幫助,將不勝感激
考慮使用PostSharp-診斷 - 工具包(問題http://www.sharpcrafters.com/blog/post/Configuring-PostSharp-Diagnostics- Toolkits.aspx)而不是編寫自己的實現。順便說一句,它是開源的。 –