C#的FTP服务器软件系统的设计与实现(14)
时间:2017-04-28 09:26 来源:毕业论文 作者:毕业论文 点击:次
{ string[] Item = new string[4]; Item[0] = Log["ErrorSource"].ToString(); Item[1] = ((DateTime)Log["DateTime"]).ToString(ApplicationSettings.DateTimeFormat); Item[2] = Log["Exception"].ToString(); Item[3] = Log["Message"].ToString(); lstExceptionList.Items.Add(new ListViewItem(Item)); } }//清空日志列表 void CancelSearch_Click(object sender, EventArgs e) { CancelSearch = MessageBox.Show("Are you sure to cancel the searching operation?", "Advanced FTP Server", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; }//取消日志搜索 写入日志方法: namespace AdvancedFTPServer { internal enum LogSource { HTTP, FTP } internal class ApplicationLog { static FileStream LogStream; static StreamWriter Log; static string LogFilePath; internal static bool EnableLogging = true; [MethodImpl(MethodImplOptions.Synchronized)] internal static void Write(LogSource Source, Exception Ex) { if (Ex == null || !EnableLogging) return; if (Ex.InnerException != null) Ex = Ex.InnerException; try { if (!Directory.Exists(ApplicationSettings.DataPath + "Logs\\")) Directory.CreateDirectory(ApplicationSettings.DataPath + "Logs\\"); LogFilePath = ApplicationSettings.DataPath + "Logs\\LOG." + DateTime.Today.ToString("yyyy-MM-dd") + ".EXCEPTION"; LogStream = new FileStream(LogFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); Log = new StreamWriter(LogStream, Encoding.UTF8); (责任编辑:qin) |