Got logging to work. Have to fclose before the program terminates