/// <summary> /// 解析日志 /// </summary> /// <param name="sshLog"></param> /// <param name="date">日期 格式为20140711</param> /// <returns></returns> private string Analyse(SSHLog sshLog, out string date) { date = sshLog.DateTime.ToString("yyyyMMdd"); string time = string.Format("{0:t}", sshLog.DateTime); string message = date + " " + time + " " + sshLog.Message; return(message); }
/// <summary> /// 写日志 /// </summary> /// <param name="sshLog"></param> public void WriteLog(SSHLog sshLog) { //解析日志内容 string date = string.Empty; string message = Analyse(sshLog, out date); #region 确定日志路径 string path = BaseLogPath + "\\" + date; FileSystemUtil.MakeDir(path); path += "\\" + date + "SSH-" + sshLog.LogType.ToString() + ".txt"; #endregion try { //写日志 using (var sw = new StreamWriter(path, true)) { sw.WriteLine(message); } } catch (Exception ex) { LogManager.WriteLogFirstLayer(LogFile.Error, ex); } }