SafeLogger.mqh appends one line to a file shared by several EAs without losing lines. It opens the file exclusively (no FILE_SHARE_WRITE), retries up to 8 times with 40 ms between attempts (320 ms of patience) while another EA holds the file, and prints a loud error with the lost line when the retries run out.
Functions: SafeLogWrite(file, fields) prepends the TimeLocal() timestamp and the symbol and appends time;symbol;fields ; SafeLogHeader(file, header) writes the header once if the file does not exist yet.
Demo inputs: InpFile = "demo_log.csv", InpLines = 200, InpSafeMode = true (false reproduces the wrong way, with FILE_SHARE_WRITE).
The demo prints the mode, the calls that returned success, the line count before and after, the time taken, and >>> N LINE(S) LOST with a successful FileOpen when lines went missing.
Limit: the loss only shows with concurrent writers. Drag the script onto four charts at once with InpSafeMode = false to see it; on a single chart there is no contention and both modes give the same count.