/// <summary> /// Write a string into LogFile /// </summary> /// <param name="channel"> /// The channel. /// </param> /// <param name="data"> /// The data. /// </param> /// <param name="sender"> /// The sender. /// </param> public static void WriteString(string channel, string data, string sender) { // Make sure the config has chat logging enabled. if (!m_bEnabled) { return; } /* * //Check if this is the first entry for this channel. * if (!m_LogFiles.ContainsKey(Channel)) * { * LoadLog(Channel); * } */ // Check if it's a new day and we must close current log // for channel, and open a new one. if (CheckLogRefresh(channel)) { LoadLog(channel); } LoadLog(channel); ChatLog logFile = LogFiles[channel]; DateTime timestamp = DateTime.Now; StringBuilder logEntry = new StringBuilder(); logEntry.Append("["); logEntry.Append(timestamp.ToString("hh:mm")); logEntry.Append("] "); logEntry.Append(sender); logEntry.Append(": "); logEntry.Append(data); logFile.Stream.WriteLine(logEntry.ToString()); logFile.Stream.Close(); }
/// <summary> /// The load log. /// </summary> /// <param name="Channel"> /// The channel. /// </param> private static void LoadLog(string Channel) { if (LogFiles.ContainsKey(Channel)) { LogFiles[Channel].Stream.Close(); } DateTime newLogDate = DateTime.Now; ChatLog newLog = new ChatLog(); newLog.CreationDate = newLogDate; newLog.Stream = null; string logFilename = GetLogString(Channel, newLogDate); if (!File.Exists(logFilename)) { newLog.Stream = new StreamWriter(logFilename, false); } else { newLog.Stream = new StreamWriter(logFilename, true); } LogFiles[Channel] = newLog; }