这是一个向文件写入信息的程序。现在就是操作信息如何获得并转换成sMsg字符串
//写日志文件
public static void WriteLog(string sMsg)
{
if (sMsg != "")
{
Random randObj = new Random(DateTime.Now.Millisecond);
int file = randObj.Next() + 1;
string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + file + ".txt";
try
{
FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath(filename));
if (!fi.Exists)
{
using (StreamWriter sw = fi.CreateText())
{
sw.WriteLine(DateTime.Now + "\n" + sMsg + "\n");
sw.Close();
}
}
else
{
using (StreamWriter sw = fi.AppendText())
{
sw.WriteLine(DateTime.Now + "\n" + sMsg + "\n");
sw.Close();
}
}
}
catch
{
}
}
}