public static FileLoggerQueue GetInstance(string filePath) { checked { if (!Instances.ContainsKey(filePath)) { Instances[filePath] = new FileLoggerQueue(); FileInfo file = new FileInfo(filePath); if (file.Exists) { int logId = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; bool can = true; int moreThan = 0; while (can) { string text = string.Format("{0}{1}", file.Name, logId); if (moreThan > 0) { text = string.Format("{0}_{1}", text, moreThan); } FileInfo newFile = new FileInfo(Path.Combine(file.DirectoryName, text + file.Extension)); if (newFile.Exists) { moreThan++; } else { File.Move(filePath, newFile.FullName); can = false; } } } } return(Instances[filePath]); } }
public FileLogger(string logFilePath) { LogFilePath = logFilePath; FileLoggerQueue = FileLoggerQueue.GetInstance(logFilePath); }