Tracing has long been the "Hello, world" sample of Aspect-Oriented
Programming. PostSharp does not make exception: tracing is still the first
aspect visible on the home page, and most of early PostSharp bloggers did
demonstrate AOP on a tracing aspect.
Yet, as tracing is a fundamental part of any non-trivial application, some
advanced tools are available to .NET developers. Two of them deserve a special
attention since their vendor provides aspects that can be directly used with
Don't ask me to compare these toolkits: they are actually sharp competitors.
Both have good web sites and a free trial, so I can only recommend you give them
both a try! And both have identified PostSharp as a natural complement to their
product (Gibraltar being the first).
I have a special moral debt to Jay Cincotta, one of the guys behind
Gibraltar, since he recorded an amazing webcast of using PostSharp and Gibraltar
together. Jay, thank you very much for this video, I know how hard it is to
With these aspects you can declaratively add Gibraltar logging to your
programs by simply tagging whatever methods, classes or namespaces you wish.
This lets you add powerful logging to your applications without the effort,
complexity or clutter of writing procedural logging code.
- [GTrace] logs entry and exit from tagged methods including
appropriate message indentation.
- [GTraceField] logs every change in value of a tagged field.
- [GException] logs exceptions at the point they are raised. This
is a handy safe guard to ensure that both handled and unhandled exceptions
are logged by Gibraltar.
- [GTimer] lets you graph method execution time in Gibraltar
providing invaluable information to identify bottlenecks and optimize
These aspects (not the toolkit itself) are open-source and are hosted on
Google Code at
For more information, see
with Gibraltar on their web site.
Following Gibraltar, SmartInspect provides similar aspects:
- [SiTrace] automatically generates two log messages for
each method call: one for entering a method and one when a method exits. You
can also log the passed method arguments (when entering a method) and the
method result (when exiting a method), respectively.
- [SiException] records all exceptions occurring in
methods enhanced by the aspect.
- [SiField] lets you automatically record any changes to
values of object or class fields.
The aspects can be downloaded from
SmartInspect Resources & Extras
(look for SmartInspect PostSharp Adapter).
For more information, see
Aspect-oriented logging for .NET with PostSharp and SmartInspect
on their web site.
Support for Other Logging Frameworks
If you're interested in using PostSharp with Log4Net, remember to check out
Log4PostSharp, a project of Michal Dabrowski and Mark Kharitonov. Note that,
contrarily to what's now offered by Gibraltar and SmartInspect, Log4PostSharp
directly emits optimal instructions, resulting in much better runtime
performance. This is not a feature of the logging framework but of the aspect
Interestingly, there is also some aging project from Eclipse,
Build to Manage for .NET, providing PostSharp aspects for the IBM Tivoli
PostSharp Emerged as the De-Facto Standard
What's happening there is that PostSharp is emerging as the de-facto standard
for aspect-oriented programming on Microsoft .NET, just like AspectJ is for
PostSharp 2.0 has been designed for the multi-vendor scenario, so that
multiple aspects shall merge robustly when applied on the same element of code,
even if these aspects come from different vendors who don't know about each
This means that ISVs can confidently rely on PostSharp to deliver aspects to
their own customers. Good to know: the upcoming price structure shall make it
very affordable for small ISVs to redistribute PostSharp free of royalties --
while enabling their own customers to use all professional features of PostSharp
2.0, including the IDE extension, in conjunction with their software.
I am pleased to announce PostSharp 2.0 CTP 2, available for
Additionally to uncountable bug fixes, this new CTP brings the following
- Support for .NET 4.0;
- Support for Microsoft Visual Studio 2010 (including the IDE extension);
- Support for Mono 2.4.
This release is hardcoded to expire on February 1st, 2010. It is not possible
to purchase a license yet.
The following features are not included in CTP 2 but are planned for
a future preview of 2.0:
- Conceptual Documentation;
- Reference Documentation and Conceptual Documentation of PostSharp SDK
(previously PostSharp Core);
- Support for Silverlight and Compact Framework.
Continue good work submitting feedback on PostSharp
I'll present PostSharp and Aspect-Oriented Programming at MS Fest 2009, taking place in Prague, Czech Republic, this week-end (November 28th and 29th), and organized by students of the Math-Phys Institute of the Charles University.
My presentation will be in Czech -- I'm getting used to be the only one not to make the show in his mother tongue (mine is French)...
There will be a lot of fun! I gave the same presentation in Munich, Germany last month, and it was considered an homage to Mr Bean! No, seriously guys, AOP is serious stuff!