Moved to the questions forum.
It is not related to the log command or the if statement. Accessing an uninitialized LayoutValues object is a programming mistake. Your code causes a division by 0.
The difference in the behavior is related to the debugger pipeline. You can see it by cleaning the project after you make a change.
Anyway, I will make this method (ApproximateScreenSize) throw an exception when the Scale is zero.