Notes

2.1 Demo/basic License had expired
Installed 3.x via VS2010 Extension Manager
2.1 was still installed on the system.
Had to uninstall via Control Panel
Had to close Visual Studio
Had to kill a 3.1 server task (not sure where it came from)
Then Followed directions at Installing PostSharp
Re-opened VS
removed existing references to Postsharp
Per instructions, right-clicked onto Project, clicked on Add PostSharp

 

 

original notes 2012 October

Installed to project via Nu Get (I believe)
Although I do have Post Sharp installed @ C:\program files (x86)\PostSharp

 

I think I may have used this tutorial: http://www.codeproject.com/Articles/337564/Aspect-Oriented-Programming-Using-Csharp-and-PostS

 

 

I am using the markup [LoggingAttribute]

 

which is defined in a utilities.cs file as follows:

 

using System;
using log4net;
using PostSharp.Aspects;

namespace MyProject
{

    [Serializable]
    public class LoggingAttribute : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionArgs args)
        {
            try
            {
                var msg = string.Format("Entering {0}.{1}.", args.Method.DeclaringType.Name, args.Method.Name);

                LogManager.GetLogger(args.Instance.GetType()).Debug(msg);
            }
            catch (Exception ex)
            {
                // for static methods, args.Instance is always null
                // not sure how to handle this...
                //LogManager.GetLogger(args.Instance.GetType()).Debug(ex.ToString());

                // see my comment @ http://stackoverflow.com/questions/6559589/postsharp-newbie-why-is-args-instance-null

            }
        }

        public override void OnExit(MethodExecutionArgs args)
        {
            try
            {
                var msg = string.Format("Exiting {0}.{1}.", args.Method.DeclaringType.Name, args.Method.Name);
                LogManager.GetLogger(args.Instance.GetType()).Debug(msg);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(args.Instance.GetType()).Debug(ex.ToString());
            }
        }
    }
}

 

 

 

http://stackoverflow.com/questions/417163/anyone-with-postsharp-experience-in-production
Why is args.Instance (sometimes) null?
http://www.sharpcrafters.com/solutions/logging