net\2.0\release
directory of the log4net binaries download)
[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);
}
}
Cannot serialize the aspects: Type 'log4net.Core.LogImpl' in Assembly 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' is not marked as serializable.
How can I make the log4net.Core.LogImpl
serializable so that I can compile this solution?
Based on the comments from Grant and mtsiakiris I solved this problem by adding the [NonSerialized]
attribute to the field like this:
[NonSerialized]
ILog _logger = LogManager.GetLogger("MethodBoundaryAspect");
which then just ignored it during serialization. The reason this occurs is because PostSharp needs to serialize the attribute during its IL generation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With