/// Represents the log level, level of value 4 is the most important
/// </summary>
public enum LogLevel : int
{
LvlConfig = 6, //登录,修改配置操作的记录
LvlFolow = 5, //流程中的记录
LvlMax = 4,
LvlHigh = 3,
LvlMedium = 2,
LvlLow = 1,
LvlMin = 0,
}
//读取日志文件
public string ReadLogFile(bool message)
{
String pathDirLog = ApplicationStructureManager.Instance().GetApplicationLogFolder();
//LogFile Path
//String logFileName = ApplicationStructureManager.Instance().GetApplicationLogName();
String logFileName = String.Format(ApplicationStructureManager.Instance().GetApplicationLogName(), DateTime.Now.DayOfWeek.ToString());
FileManager.Instance().CreateDirectoryFromPath(pathDirLog);
String pathLog = pathDirLog + logFileName;
FileManager.Instance().CreateFileFromPath(pathLog, false);
string readLogFile=File.ReadAllText(pathLog);
this.logFile = FileManager.Instance().GetFileInfoFromPath(pathLog);
//Default mode
//TMP should be modified form the settings after
this.LogLevel = LogLevel.LvlMin;//TMP
//TMP DEV
this.printToConsole = true;
return readLogFile;
}
/// <summary>
/// Return the log folder path for the application
/// </summary>
/// <returns>the path of the logs</returns>
public String GetApplicationLogFolder()
{
String logPath = null;
XmlNode root = this.xmlAppStructure.GetElementsByTagName(XmlTypes.ROOT_ELE)[0];
logPath = root.Attributes[XmlTypes.ROOT_ATT_LOG_PAT].Value;
//TMP LOG If not found ?!
return logPath;
}
/// <summary>
/// Return the name of the logfile
/// </summary>
/// <returns>the name of the log file</returns>
public String GetApplicationLogName()
{
String logName = null;
XmlNode root = this.xmlAppStructure.GetElementsByTagName(XmlTypes.ROOT_ELE)[0];
logName = root.Attributes[XmlTypes.ROOT_ATT_LOG_NAM].Value;
//TMP LOG If not found ?!
return logName;
}
/// <summary>
/// Create a Directory from the given path
/// </summary>
/// <param name="pPath">Directory complete path</param>
/// <returns>The DirectoryInfo corresponding to the directory, or null otherwise</returns>
public DirectoryInfo CreateDirectoryFromPath(String pPath)
{
DirectoryInfo di = null;
if (!String.IsNullOrEmpty(pPath))
{
if (!Directory.Exists(pPath))
{
Directory.CreateDirectory(pPath);
}
di = new DirectoryInfo(pPath);
}
return di;
}
/// <summary>
/// Create a File from the given path
/// </summary>
/// <param name="pPath">File complete path</param>
/// <param name="overwrite">overwrite if existing file found</param>
/// <returns>The FileInfo corresponding to the path, or null otherwise</returns>
public FileInfo CreateFileFromPath(String pPath, Boolean pOverwrite)
{
FileInfo fi = null;
if (!String.IsNullOrEmpty(pPath))
{
// if the file doesn't exist or must overwrite
if (!File.Exists(pPath) || pOverwrite)
{
// close the stream else the file is locked
FileStream fs = File.Create(pPath);
fs.Close();
}
fi = new FileInfo(pPath);
}
return fi;
}
/// <summary>
/// Return the File information object for a given path
/// </summary>
/// <param name="pPath">The path of the file</param>
/// <returns>The FileInfo of the corresponding file if found, null otherwise</returns>
public FileInfo GetFileInfoFromPath(String pPath)
{
FileInfo fi = null;
if (!String.IsNullOrEmpty(pPath))
{
if (File.Exists(pPath))
{
fi = new FileInfo(pPath);
}
}
return fi;
}