Error when compiling c# project in VS2012 when using Postsharp

Posted by Thewads on Stack Overflow See other posts from Stack Overflow or by Thewads
Published on 2012-10-30T10:58:45Z Indexed on 2012/10/30 11:01 UTC
Read the original article Hit count: 270

Filed under:
|
|

I am currently working on a project where we were wanting to add PostSharp functionality.

I have set up my Postsharp attribute as so

[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

© Stack Overflow or respective owner

Related posts about c#

Related posts about nlog