/// <summary>
/// 获得文本文件中错误消息的值
/// </summary>
/// <param name="strKey"></param>
/// <returns></returns>
public string GetMsgValue(string strKey)
{
string path = Environment.CurrentDirectory.ToString() + "\\MessageBook.txt";
WriteLog(path);
string retValue = string.Empty;
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
if (line.ToString() != string.Empty)
{
string s = line.ToString();
string[] words = s.Split('-');
if (words[0].ToString() == strKey)
{
retValue = words[1].ToString();
break;
}
}
}
return retValue;
}
/// <summary>
/// 简单的写Log方法
/// </summary>
/// <param name="strLogInfo"></param>
public void WriteLog(string strLogInfo)
{
string fileName = Environment.CurrentDirectory.ToString()+@"\log.txt";
using (StreamWriter sw = new StreamWriter(fileName, true))
{
sw.WriteLine(strLogInfo);
sw.WriteLine("--------------------------");
sw.Flush();
sw.Close();
}
}
/// 获得文本文件中错误消息的值
/// </summary>
/// <param name="strKey"></param>
/// <returns></returns>
public string GetMsgValue(string strKey)
{
string path = Environment.CurrentDirectory.ToString() + "\\MessageBook.txt";
WriteLog(path);
string retValue = string.Empty;
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
if (line.ToString() != string.Empty)
{
string s = line.ToString();
string[] words = s.Split('-');
if (words[0].ToString() == strKey)
{
retValue = words[1].ToString();
break;
}
}
}
return retValue;
}
错误信息文本文件格式:
ErrMsg1-エラー1
ErrMsg2-エラー2
/// <summary>
/// 简单的写Log方法
/// </summary>
/// <param name="strLogInfo"></param>
public void WriteLog(string strLogInfo)
{
string fileName = Environment.CurrentDirectory.ToString()+@"\log.txt";
using (StreamWriter sw = new StreamWriter(fileName, true))
{
sw.WriteLine(strLogInfo);
sw.WriteLine("--------------------------");
sw.Flush();
sw.Close();
}
}