一个挺实用的方法,可以参考
/// <summary>
/// 创建并写入文件-日志(.txt)
/// </summary>
/// <param name="content">内容</param>
/// <returns>true:写出正确;反之,false;</returns>
public static bool WritingLogsToTxt(string content)
{
string path = string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, @"Log\NCR\");
FileStream stream = null;
StreamWriter writer = null;
bool flag = false;
try
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = string.Format(@"{0}\Log_{1}{2}", path, DateTime.Now.ToString("y