public static object LockingTarget = new object(); public void LogToFile(string msg) { lock(LockingTarget) { //append to file here as fast as possible } }