In C#, Is it possible to add annotations to methods that can execute before, during, and in case of an error as the method runs?
<p>I had the thought that it'd be nice to move logging details outside of a method if it were possible. My first thought was to wonder if this could be done through annotations or attributes. For example</p>

<pre><code>[LogBeforeRunning("Foo is about to be run.")]
[LogAfterRunning("Foo has been run.")]
[LogOnError("Foo ran into some errors while running.")]
public void Foo() 
{
    //do something
}
</code></pre>

<p>I know the ASP.NET MVC framework has something like this, but I don't know how much wiring this would take to setup. Another question worth asking is would this even be of value? I think it would, but the logging wouldn't have pertinent variable information so I would still need more details than this.</p>

<p>Still, how would one go about something like this? I'm curious to know if it is possible.</p>