{"id":10195,"date":"2017-05-26T14:00:00","date_gmt":"2017-05-26T14:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/premier_developer\/?p=10195"},"modified":"2019-02-14T20:23:43","modified_gmt":"2019-02-15T03:23:43","slug":"using-application-insights-sdk-in-aspect-oriented-programming-aop-style-with-net","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/using-application-insights-sdk-in-aspect-oriented-programming-aop-style-with-net\/","title":{"rendered":"Using Application Insights SDK in Aspect-oriented programming (AOP) style with .NET"},"content":{"rendered":"<p>This is the second post in a series on the Application Insights SDK from Premier Developer consultant <a href=\"https:\/\/www.linkedin.com\/in\/nasir-syed-77b81188\/\" target=\"_blank\">Nasir Syed<\/a>.&nbsp; Check out his previous post <a href=\"https:\/\/blogs.msdn.microsoft.com\/premier_developer\/2017\/05\/24\/avoiding-code-pollution-when-using-application-insights-sdk\/\" target=\"_blank\">here<\/a>.<\/p>\n<hr>\n<p>In my <a href=\"https:\/\/nasirsyed.wordpress.com\/2017\/04\/27\/avoiding-code-pollution-when-using-application-insights-sdk\/\">previous<\/a> post I talked about using <em>Custom Attributes<\/em> to avoid repetition, code pollution etc., and illustrated it from a very high level to use with Application Insights API, custom events. <\/p>\n<p><em>\u201cC# \u2013 Attributes. Advertisements. An attribute is a declarative tag that is used to convey information to <b>runtime<\/b> 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\u201c<\/em> <\/p>\n<p>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, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Aspect-oriented_programming\">AOP (Aspect-oriented programming)<\/a> I also looked into <a href=\"https:\/\/www.postsharp.net\/\">PostSharp <\/a>a popular framework for AOP. I tried out few scenarios and all my thoughts started to come together, VERY COOL. During my <del>googling<\/del> (wait.. binging!!) I educated myself more and more on AOP (very interesting) I found many articles and landed on <a href=\"https:\/\/msdn.microsoft.com\/en-us\/magazine\/dn574804.aspx\">this<\/a>, it gave me great ideas on using pure .NET (<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.remoting.proxies.realproxy(v=vs.110).aspx\">RealProxy<\/a> 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. <\/p>\n<p>Read the rest on Nasir\u2019s blog <a href=\"https:\/\/nasirsyed.wordpress.com\/2017\/04\/30\/using-application-insights-sdk-in-aspect-oriented-programming-aop-style-with-net\/\" target=\"_blank\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the second post in a series on the Application Insights SDK from Premier Developer consultant Nasir Syed.&nbsp; 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, [&hellip;]<\/p>\n","protected":false},"author":581,"featured_media":37840,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[106,81,279],"class_list":["post-10195","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-permierdev","tag-net","tag-application-insights","tag-nasir-syed"],"acf":[],"blog_post_summary":"<p>This is the second post in a series on the Application Insights SDK from Premier Developer consultant Nasir Syed.&nbsp; 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, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/10195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=10195"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/10195\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/37840"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=10195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=10195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=10195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}