示例#1
0
        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}");
        }
示例#2
0
 private IStreamWriterFacade OpenNextFile(bool isFirstFile)
 {
     return(FileSystemFacade.CreateStreamWriter(GetLogFileName(isFirstFile), true, Encoding.UTF8, true));
 }