private static void StreamWrite(string msg, string callingMethod, TraceLvl traceLvl, bool force = false) { Prepare(msg, callingMethod, traceLvl); if (force) { _traceLine = msg; } using (StreamWriter sw = new StreamWriter(_fileName, true)) { sw.Write(_traceLine); } }
private static void Prepare(string msg, string callingMethod, TraceLvl traceLvl) { string logPath = ConfigurationManager.AppSettings["LogPath"] ?? DEFAULT_PATH; if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } if (!string.IsNullOrEmpty(logPath) && !logPath.EndsWith("\\")) { logPath += "\\"; } _fileName = logPath + TRACE_FILE_NAME + '_' + DateTime.Now.ToString("yyyyMMdd") + ".txt"; _traceLine = String.Format("[{0}] [{1}] [{2}] {3}", DateTime.Now.ToString("HH:mm:ss.fff"), traceLvl, callingMethod, msg); }
public static void WriteLine(string msg, string callingMethod, TraceLvl traceLvl) { StreamWriteLine(msg, callingMethod, traceLvl); }