public static void WriteTextLog(object objs)
{
try
{
DateTime time = DateTime.Now;
string path = AppDomain.CurrentDomain.BaseDirectory + "/Log/" + time.ToString("yyyy-MM") + "/";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileFullPath = path + time.ToString("yyyy-MM-dd") + ".txt";
StringBuilder str = new StringBuilder();
str.Append(objs);
StreamWriter sw;
if (!File.Exists(fileFullPath))
{
sw = File.CreateText(fileFullPath);
}
else
{
sw = File.AppendText(fileFullPath);
}
sw.WriteLine(str.ToString());
sw.Close();
}
catch (Exception)
{
}
}
项目根目录Log生成
最新推荐文章于 2023-08-09 14:28:48 发布