using ivf_tl_Entity.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ivf_tl_Service
{
public class CSVHelper
{
//目录
public static string path = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\incubator_logs\\";
//死锁
private static object loglock = new object();
public static void Write(string filename, string content)
{
lock (loglock)
{
try
{
if (!Directory.Exists(path))//如果日志目录不存在就创建
{
Directory.CreateDirectory(path);
}
//创建或打开日志文件,向日志文件末尾追加记录
StreamWriter mySw = File.AppendText(path + filename);
//向日志文件写入内容
string write_content = content;
mySw.WriteLine(write_content);
//关闭日志文件
mySw.Close();
}
catch
{
}
}
}
///
/// 写文件,覆盖false,追加true
///
/// 文件名
/// 内容
/// 覆盖false,追加true
public static void WriteFile(string filename, string content, bool isAppend)
{
lock (loglock)
{
try
{
if (isAppend)
{
if (!File.Exists(filename))
{
return;
}
}
else
{
FileStream fs = System.IO.File.Create(filename);
fs.Close();
}
using (System.IO.StreamWriter mySw = new System.IO.StreamWriter(filename, isAppend, System.Text.Encoding.UTF8))
{
mySw.WriteLine(content);
mySw.Flush();
mySw.Close();
}
}
catch (Exception ex)
{
Log4netHelper.WriteLog("写CSV文件", ex);
}
}
}
}
}