using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; namespace EndaccountManage { public class LogHelper { public static string path = System.AppDomain.CurrentDomain.BaseDirectory; public static void WriteServiceLog(string LogData, string LogFileName = "") { LogData = DateTime.Now.ToLongTimeString() + ":" + LogData; string LogName = "错误日志_" + System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString() + ".log"; if (LogFileName != "") { LogName = LogFileName; } string filename = path + "\\" + LogName; FileStream fs = new FileStream(filename, FileMode.OpenOrCreate); fs.Seek(0, SeekOrigin.End); byte[] _data = new UTF8Encoding().GetBytes(LogData + "\r\n\r\n"); fs.Write(_data, 0, _data.Length); fs.Flush(); fs.Close(); } public static void WriteServiceLog2(string LogData) { LogData = DateTime.Now.ToLongTimeString() + ":" + LogData; string LogName = "日志_Success" + System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString() + ".log"; string filename = path + "\\" + LogName; FileStream fs = new FileStream(filename, FileMode.OpenOrCreate); fs.Seek(0, SeekOrigin.End); byte[] _data = new UTF8Encoding().GetBytes(LogData + "\r\n"); fs.Write(_data, 0, _data.Length); fs.Flush(); fs.Close(); } } }