I have written a script which will write log file for a period of time or when some conditions are met by using StreamWriter class. I want to ask if by any chance that the application is quit, exit or closed by user (not crash) while it is still writing log file. Will Unity stop immediately or will it wait the method to finish writing log file first and then quit? In other word, I want to know if there is a chance that the script will stop writing log file halfway when the unity is quit or not. Note that I've worked in editor mode. Quit means press the stop button.
It really depends on how you write your code. There is always a chance Unity will quit in the middle of the writing of the log, for example, if it's done as a loop. Just like a game has some kind of game loop - you can still quit a game whenever you want.
You can use Application.CancelQuit() to make sure Unity doesn't close during those operations. Check out the example in the link for some ideas on how to implement it.