I get "Unable to serialize aspects: type" log4net.Core.LogImpl "in the assembly" log4net ... "" How can I make serializable?

Environment

  • Windows 7 x64
  • PostSharp 2.1.7.30 installed
  • PostSharp 2.1.7.29 (link obtained from PostSharp installation directory)
  • log4net 1.2.11.0 (link obtained from the net\2.0\releaselog4net binary download directory )
  • ASP.NET 2.0 Application
  • Visual Studio 2010 SP1

Format

[Serializable]
public class MethodBoundaryAspect : PostSharp.Aspects.OnMethodBoundaryAspect
{
    ILog _logger = LogManager.GetLogger("MethodBoundaryAspect");

    public override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args)
    {
        _logger.DebugFormat("The user {0} entered the method {1} at {2}.",
            HttpContext.Current.Profile.UserName,
            args.Method.Name,
            DateTime.Now);

        base.OnEntry(args);
    }

    public override void OnExit(PostSharp.Aspects.MethodExecutionArgs args)
    {
        _logger.DebugFormat("The user {0} exited the method {1} at {2}.",
            HttpContext.Current.Profile.UserName,
            args.Method.Name,
            DateTime.Now);

        base.OnExit(args);
    }

    public override void OnException(PostSharp.Aspects.MethodExecutionArgs args)
    {
        _logger.DebugFormat("The user {0} was executing the method {1} when an unhandled exception occurred at {2}.{3}{4}",
            HttpContext.Current.Profile.UserName,
            args.Method.Name,
            DateTime.Now,
            Environment.NewLine,
            args.Exception.ToString());

        base.OnException(args);
    }
}

Compilation error

Cannot serialize aspects: Enter 'log4net.Core.LogImpl' in Assembly 'log4net, Version = 1.2.11.0, Culture = neutral, PublicKeyToken = 669e0ddf0bb1aa2a' is not marked as serializable.

How can I make serializable log4net.Core.LogImplso that I can compile this solution?

+5
1

Grant mtsiakiris, , [NonSerialized] :

[NonSerialized]
ILog _logger = LogManager.GetLogger("MethodBoundaryAspect");

. , PostSharp IL.

+10

All Articles