Tuesday, 15 January 2013

Using PostSharp to monitor WebServices Calls (deployed via TeamCity to Azure)

I just added PostSharp StarterEdition to TeamMentor

I’ve always been a fan of AoP / PostSharp, and as I need to add a number of method-driven-events-mapped-as-attributes, the time has come to use PostSharp (which is also much more mature than a couple years ago).

The registration, download and install was quite smooth

Here is a variation of the Getting Started with PostSharp example in TeamMentor’s code:

image

With this in place, all we need to do to get callbacks on Method's invocations is to add the TraceAttribute (created above and shown below)

image

This example will give us an log entry on TM_WebServices ctror Enter and Leave:

image

Which is VEEEEERRRYYY powerful :)

Note: to make this work in TeamCity and Azure, I had to add PostSharp via NuGet and include a bunch of PostSharp dependencies (inside the package folder). I managed to removed a number of files so that not all 10Mbs of stuff (included by default in PostSharp NuGet package) was needed. For reference here is the Commit with the files I needed to add.