tijian_tieying/web/Common/SaveLog.cs
2025-02-20 12:14:39 +08:00

46 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
using System.Text;
namespace ZWL.Common
{
public static class SaveLog
{
public static void Logs(string , string , string )
{
try
{
//文件夹存在验证
if (!Directory.Exists())
{
Directory.CreateDirectory();
}
//默认添加日志日期前缀
StringBuilder logName = new StringBuilder();
string date = System.DateTime.Today.ToString("yyyy-MM-dd" + "-");
logName.Append(date);
if (!string.IsNullOrEmpty())
{
logName.Append();
}
logName.Append(".log");
string filePath = + "\\" + logName.ToString();
FileStream fs;
if (!File.Exists(filePath))
{
fs = File.Create(filePath);
}
else
{
fs = File.Open(filePath, FileMode.Append);
}
//内容前默认添加时间
string strToWrite = System.DateTime.Now.ToString() + "" + + "\r\n";
byte[] b = System.Text.Encoding.Default.GetBytes(strToWrite);
fs.Write(b, 0, b.Length);
fs.Close();
}
catch { }
}
}
}