private string GetLogFileName(bool isFirstFile) { if (isFirstFile) { FileSystemFacade.CreateDirectory(logPath); } var logFileNamePart = BuildLogFileName(isFirstFile); var triedFileNames = new StringBuilder(); for (var i = 0; i < MaxTriesForDuplicatedFileNames; ++i) { var currentFileName = BuildFullLogFilePath(logFileNamePart.ToString(), i); if (!FileSystemFacade.FileExists(currentFileName)) { return(currentFileName); } triedFileNames.AppendLine(currentFileName); } throw new InvalidOperationException($"Failed to generate unique log filename after {MaxTriesForDuplicatedFileNames} tries. Following files exist:\n{triedFileNames}"); }
private IStreamWriterFacade OpenNextFile(bool isFirstFile) { return(FileSystemFacade.CreateStreamWriter(GetLogFileName(isFirstFile), true, Encoding.UTF8, true)); }