添加项目文件。

This commit is contained in:
zhouyunhao
2024-08-13 10:31:46 +08:00
parent 771a9cc09d
commit 6f4c64175d
76 changed files with 19060 additions and 0 deletions

50
C-Windows-1/Log.cs Normal file
View File

@@ -0,0 +1,50 @@
using System;
using System.IO;
namespace C_Windows_1
{
class Log
{
/// <summary>
/// log日志txt的
/// </summary>
/// <param name="Log1">内容</param>
/// <param name="name">名字</param>
/// <param name="path">路径</param>
public void Logmsg(string Log1)
{
#region
string Log = "";
string path = System.Environment.CurrentDirectory + "\\MES_Log";
Log += Log1 + "\r\n";
//生成目录
//创建文件夹
if (Directory.Exists(path) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(path);
}
// 判断文件是否存在不存在则创建否则读取值显示到txt文档
if (!System.IO.File.Exists(path + "/" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt"))
{
FileStream fs1 = new FileStream(path + "/" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt", FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(Log);//开始写入值
sw.Close();
fs1.Close();
}
else
{
FileStream fs = new FileStream(path + "/" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt" + "", FileMode.Append, FileAccess.Write);
StreamWriter sr = new StreamWriter(fs);
sr.WriteLine(Log);//开始写入值
sr.Close();
fs.Close();
}
#endregion
}
}
}