namespace com.hitrust.b2b.trustpay.client { using System; using System.IO; using System.Text; public class LogWriter { internal StreamWriter iLogFile; public LogWriter() { this.iLogFile = null; } public LogWriter(Stream aLogFile) { this.iLogFile = null; this.iLogFile = new StreamWriter(aLogFile, Encoding.GetEncoding("GB2312")); } public virtual void closeWriter() { try { this.iLogFile.Close(); } catch (Exception) { } } public virtual void log(string aLogString) { if (this.iLogFile == null) { Console.Out.Write(aLogString); } else { try { char[] chArray = aLogString.ToCharArray(); for (int i = 0; i <= chArray.Length; i++) { if (chArray[i] != '\r') { if (chArray[i] == '\n') { this.iLogFile.Write("\n "); } else { this.iLogFile.Write(chArray[i]); } } } } catch (Exception) { } } } public virtual void logNewLine(string aLogString) { if (this.iLogFile == null) { Console.Out.WriteLine(aLogString); } else { string str = new HiCalendar().toString("%Y/%m/%d-%H:%M:%S "); try { this.iLogFile.Write("\n" + str); char[] chArray = aLogString.ToCharArray(); for (int i = 0; i <= chArray.Length; i++) { if (chArray[i] != '\r') { if (chArray[i] == '\n') { this.iLogFile.Write("\n "); } else { this.iLogFile.Write(chArray[i]); } } } } catch (Exception) { } } } } }