using System; using System.IO; using System.Collections.Generic; using System.Text; namespace STMes { public interface ILogService { void WriteLog(string message); } public class CoreWriteLogFile : ILogService { private static object lockObj = new object(); #region ILogService ³ΙΤ± public void WriteLog(string message) { WriteLog(message, LogInfoLevel.Message, "", ""); } public void WriteLog(string message, LogInfoLevel level) { WriteLog(message, level, "", ""); } public void WriteLog(string message, string UserID, string codeInfo) { WriteLog(message, LogInfoLevel.Message, UserID, codeInfo); } public void WriteLog(string message, LogInfoLevel level, string UserID, string codeInfo) { lock (lockObj) { try { string logFile = System.Environment.CurrentDirectory + "/log/" + "DBProxy_"+DateTime.Now.ToString("yyyyMMdd") + "_log.log"; FileInfo fi = new FileInfo(logFile); StreamWriter sw = null; try { if (fi.Exists) sw = fi.AppendText(); else sw = fi.CreateText(); string str = ""; if (level == LogInfoLevel.Error) str = ">>> Error <<<"; else str = ">>> Message <<<"; string title = ">>> " + DateTime.Now + " <<<"; title += str; if (UserID != "") { title += ">>> " + UserID + " <<<"; } if (codeInfo != "") { title += ">>> " + codeInfo + " <<<"; } sw.WriteLine(title); sw.WriteLine(message); sw.WriteLine(); sw.Flush(); } finally { if (sw != null) sw.Close(); } } catch { // do nothing. } } } #endregion } public enum LogInfoLevel { Error = 1, Message = 2 } }