Using Application Insights SDK in Aspect-oriented programming (AOP) style with .NET


This is the second post in a series on the Application Insights SDK from Premier Developer consultant Nasir Syed.  Check out his previous post here.


In my previous post I talked about using Custom Attributes to avoid repetition, code pollution etc., and illustrated it from a very high level to use with Application Insights API, custom events.

“C# – Attributes. Advertisements. An attribute is a declarative tag that is used to convey information to runtime about the behaviors of various elements like classes, methods, structures, enumerators, assemblies etc. in your program. You can add declarative information to a program by using an attribute“

The problem I am trying to solve here is to separate the Application Insights SDK code, hide it from the developer and simplify adding the functionality to Classes, Methods and other dependencies that need to be tracked for performance, logging and auditing. I ran my thought process with my friends and fellow workers Alex and Sujit, got some great advise from both to look further into Visual Studio Profiler and Aspects based development, AOP (Aspect-oriented programming) I also looked into PostSharp a popular framework for AOP. I tried out few scenarios and all my thoughts started to come together, VERY COOL. During my googling (wait.. binging!!) I educated myself more and more on AOP (very interesting) I found many articles and landed on this, it gave me great ideas on using pure .NET (RealProxy Class) to implement a solution. Digging more into RealProxy and attributing and going through many posts and techniques certainly helped. Making the long story short I was able to assemble my approach that can be used for Profiling methods and classes for performance, logging and auditing using the AOP and attributing approach, that can simplify injecting Application Insights API into any application. I am sure it can be greatly enhanced per implementations but this can definitely get you started.

Read the rest on Nasir’s blog here.

Comments (0)

Skip to main content