Added logging to ModelManagerException handling

Added logging for easier debugging of SQL errors. It should work with 2.2 and master too, so please merge it to those branches too.