write to buffer & critical section buufer for writelog