Fixed null reference exception getting the logger

Fixes an issue where the current stackframe can contains null values.

This issue can be caused by the just-in-time compiler when it chooses to
inline short, repeatedly called methods.

See:
http://stackoverflow.com/questions/3575425/why-does-the-throw-a-nullreferenceexception-in-a-static-method