[C#] 纯文本查看 复制代码 /// <summary>
/// 写日志
/// </summary>
/// <param name="strMsg"></param>
/// <param name="strFileName"></param>
public static void WriteLogContent(string strFileName,string strMsg)
{
try
{
strMsg += " " + System.DateTime.Now + "\r\n";
string strPath = System.AppDomain.CurrentDomain.BaseDirectory + "/" + strFileName;
if (!File.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
string sname = System.DateTime.Now.ToString("yyyy-MM-dd");
FileStream fs = new FileStream(strPath + "/" + sname + ".csv", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.Write(strMsg);
sw.Flush();
sw.Close();
}
catch
{ }
}
第一个参数是你的路径 第二个是内容
内容就是你的随机数
然后做个计时器 每天执行这个方法就行了
|