Flush log file on critical error

It often happens that the game crashes and leaves the log file truncated, without the last part with the error message. Instead, if the log windows is open, the error message is always visible in it. Would it be possible to force a flush on the log file right after a critical error, so that the error message is written for sure?

-FORCELOGFLUSH

Thank you, I did not know that. I assume it flushes all log messages, not just crash ones. If this is true it is not a good idea to use it by default, since it would affect game performance. I think a good default should be that just crash messages are flushed.

yes, it should only be used in development

Here is my helper function to solve the problem:

void Helper::SaveToLog(const TCHAR *text)
{
	FString FileName = FPaths::AutomationLogDir() + TEXT("game.log");

	TCHAR *eol = TEXT("\n");

	errno_t err;
	FILE *f;

	err = _tfopen_s(&f, *FileName, TEXT("ab"));
	if(err == 0)
	{
		fwrite(text, _tcslen(text) * sizeof(TCHAR), 1, f);
		fwrite(eol, _tcslen(eol) * sizeof(TCHAR), 1, f);
		fflush(f);
		fclose(f);
	}
}