private const string LOG_FILE = "logging"; private const string LOG_FILE_EXT = ".log"; m_strGeneralFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Config.APPDATA_PATH; public void CheckLogFile() { string file = Config.LOG_FILE; m_strLogfile = Config.LOG_FILE + Config.LOG_FILE_EXT; if (File.Exists(m_strGeneralFilePath + file + Config.LOG_FILE_EXT)) { long logFileStreamLength = 0; using (Stream logFileStream = new FileStream(m_strGeneralFilePath + file + Config.LOG_FILE_EXT, FileMode.Open, FileAccess.Read)) { logFileStreamLength = logFileStream.Length; logFileStream.Flush(); logFileStream.Close(); } //configure a default value if user does not specify the value if (string.IsNullOrEmpty(logSize)) { logSize = "1000000";//1MB will the default log file size } if (logFileStreamLength > Convert.ToInt32(logSize)) // approx. 1MB 1.000.000 { for (int i = 9; i > 0; i--) { if (i == 9) { if (File.Exists(m_strGeneralFilePath + Config.LOG_FILE + i + Config.LOG_FILE_EXT)) { File.Delete(m_strGeneralFilePath + Config.LOG_FILE + i + Config.LOG_FILE_EXT); } continue; } if (File.Exists(m_strGeneralFilePath + Config.LOG_FILE + i + Config.LOG_FILE_EXT)) { System.IO.File.Move(m_strGeneralFilePath + Config.LOG_FILE + i + Config.LOG_FILE_EXT, m_strGeneralFilePath + Config.LOG_FILE + (i + 1) + Config.LOG_FILE_EXT); } } System.IO.File.Move(m_strGeneralFilePath + Config.LOG_FILE + Config.LOG_FILE_EXT, m_strGeneralFilePath + Config.LOG_FILE + "1" + Config.LOG_FILE_EXT); using (FileStream fs = File.Create(m_strGeneralFilePath + Config.LOG_FILE + Config.LOG_FILE_EXT)) { fs.Flush(); fs.Close(); } } } else { using (FileStream fs = File.Create(m_strGeneralFilePath + Config.LOG_FILE + Config.LOG_FILE_EXT)) { fs.Flush(); fs.Close(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)