Only define and use log counter if trace logging is enabled. Causes simultaneous access warnings with running multithreaded otherwise.