/// <summary> /// flush current log continer buffer /// </summary> public void Dump() { string logstring = null; lock (continer[contineIndex]) { logstring = continer[contineIndex].ToString(); contineIndex = (contineIndex == continerSize - 1) ? 0 : contineIndex + 1; continer[contineIndex] = new BufferContiner(buffSize); } if (!string.IsNullOrEmpty(logstring)) { Dump(logstring, contineIndex.ToString()); } }
/// <summary> /// /// </summary> /// <param name="pathForFileSave">a parent path,path will be appended a \logs dir end</param> /// <param name="logsNumForEachFile">define how many logs in which file,suggested num is around how many logs create pre second</param> /// <param name="logsContinerNum">nums of logs write buffer</param> public XLog(string pathForFileSave = null, int logsNumForEachFile = 100, int logsContinerNum = 0) { folderPath = pathForFileSave ?? @"\logs"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } buffSize = logsNumForEachFile; tf = new TaskFactory(); continerSize = logsContinerNum == 0 ? Convert.ToInt32(Math.Ceiling((double)(10000 / logsNumForEachFile))) : logsContinerNum; continer = new BufferContiner[++continerSize]; contineIndex = 0; continer[0] = new BufferContiner(buffSize); outputLevel = AsyncLogLevel.ALL; }