Environment
- Windows 7 x64
- PostSharp 2.1.7.30 installed
- PostSharp 2.1.7.29 (reference retrieved from the PostSharp install directory)
- log4net 1.2.11.0 (reference retrieved from the
net\2.0\release
directory of the log4net binaries download) - ASP.NET 2.0 application
- Visual Studio 2010 SP1
Aspect
[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);
}
}
Compile Error
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?
public static ILog Logger = LogManager.GetLogger("MethodBoundaryAspect");
in theGlobal.asax
? I feel like multiple threads would cause some serious problems here as multiple users use the system. Thus going back to your statement, manual serialization. – ConativeProperties
, PostSharp is trying to serialize thefield
created for_logger
. Thus as Grant stated, I may have to do this serialization by hand. – ConativeGetLogger
is in and of itself a thread-safe type. – Desist[NonSerialized]
since the serialization is only occurring for the purposes of PostSharp to do its IL generation. – Conative