This project has moved. For the latest updates, please go here.

increase or allow configuration of _maxStreamRetries in RollingTextWriter


Currently, the number of concurrent instances of a program that's trying to use a rolling log at a given path is 5, since the running instances will lock the files log.txt, log-1.txt, log-2.txt, through log-4.txt. When the 6th concurrent instance tries to run, it fails with

System.InvalidOperationException: "Exhausted possible logfile names"
at Essential.Diagnostics.RollingTextWriter.EnsureCurrentWriter(String path)
at Essential.Diagnostics.RollingTextWriter.WriteLine(TraceEventCache eventCache, String value)

That limit of 5 is currently hard-coded due to const int _maxStreamRetries = 5; being in the RollingTextWriter class. While one option would be to just change it to a higher number, having it be configurable might be useful as well. For instance, if a given user decides they want to never write to an alternative name (failing to write to the main log file should be a fatal error for them), then they could change it to 1.

For my particular case I can just make a build with a higher limit, but it'd be nice to see this addressed in a more flexible manner for others.



zijianhuang wrote Jun 10 at 3:09 AM

Concurrent instances of a program (multiple processes) writing to a single file is always risky and slow. See the fate of file base db like Paradox and Access MDB you see.

Concurrent writes from the same process is not good either, because of the spinning nature of mechanical hard drive, unless you are using some Raid X disk.

5 is a reasonable trade-ff.

Or I had misinterpret your questions and demands?

Or you may use the process Id as part of the log file name while there's a variable for process Id in config?