Thursday, November 15, 2012

Using AOP and MemoryCache to improve performance

I've submitted an article to Code Project on a simple use of AOP and MemoryCache from .Net Framework 4.
http://www.codeproject.com/Articles/493971/Leveraging-MemoryCache-and-AOP-for-expensive-calls

Thursday, October 11, 2012

Impressed (again) with PostSharp Toolkit for Log4Net

Part of my job requires me to try different application use and configuration scenarios, in an attempt to identify potential undocumented features, also known as bugs ...

So today I was configuring a brand new virtual instance of Windows 2008 R2 Server. As I wanted to have it configured as close to production as possible, I refrained from the usual development environment convenience changes, like disabling UAC and running everything as Administrator. I have deployed a sample WCF Service Application which was enhanced by the PostSharp Diagnostics Toolkit for Log4Net. The app was deployed in a directory to which IIS_IUSRS had only read access. Initially I was puzzled as to why my log files are not being generated despite this fine tuned log4net configuration:


  <log4net>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
      <file value=".\Logs\AuMineSOA.log" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <appendToFile value="true" />
      <maximumFileSize value="10MB" />
      <maxSizeRollBackups value="5" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
      </layout>
    </appender>
    <appender name="BufferingForwardingAppender" type="log4net.Appender.BufferingForwardingAppender">
      <bufferSize value="10000" />
      <appender-ref ref="RollingFile" />
    </appender>
    <appender name="MemoryAppender" type="log4net.Appender.MemoryAppender">
      <onlyFixPartialEventData value="true" />
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="BufferingForwardingAppender" />
    </root>
  </log4net>

Than I realized that I've forgot to allow IIS_IUSRS account to write to any directory in my application. The moment I corrected it, the logs started to pour in. And that's what is so darn impressive about P#L4N (my nickname for the toolkit). It did not crash the app, it did not destabilized the webserver, it simply decided to patiently wait until the access issue is resolved. 

By the way, I hot the web service with 512 simultaneous threads to discover that the best option for high traffic logger is to buffer incoming messages to memory, and then write them to a log file, with minimal lock. Otherwise, you actually might get a server crash due to a TextWriter cross-process file access issue. 


Wednesday, October 3, 2012

Aspect Oriented Programming

There has been a new video posted on Vimeo, from my friends at SharpCrafters, titled Declutter Your Codebase With Aspect Oriented Programming. Once I've learned about AOP, I instantly became a big fun of it. It is such a time saver. Tracing and error handling, caching, code injection, are just the few things you can do with AOP and PostSharp in particular. I use the PostSharp Diagnostics Toolkit For Log4Net on pretty much every project now.