写日志

public static void writeLog(string strContent)
{
string strPath = "c:\importorderlog";
string strFileName = DateTime.Now.ToString("yyyyMMdd") + ".txt";
System.IO.FileStream fs = null;

if (!System.IO.Directory.Exists(strPath))
{
System.IO.Directory.CreateDirectory(strPath);
}
if (!System.IO.File.Exists(strPath + "\" + strFileName))
{
fs = System.IO.File.Create(strPath + "\" + strFileName);
}
if (fs == null)
fs = new System.IO.FileStream(strPath + "\" + strFileName, System.IO.FileMode.Append);
System.IO.StreamWriter sw = new System.IO.StreamWriter(fs);
sw.WriteLine(strContent);
sw.Close();
sw.Dispose();
}

原文地址:https://www.cnblogs.com/zhang-wenbin/p/7384606.html