using System; using System.Collections.Generic; using System.Text; using System.IO ; namespace Bwg.Logging { /// /// This class is a message sink that writes the message to a file /// public class FileSink : Sink, IDisposable { #region private member variables private TextWriter m_writer; #endregion #region constructor /// /// Create a new file sink given the name of the output file /// /// the output file public FileSink(string filename) { try { m_writer = new StreamWriter(filename); } catch (Exception) { m_writer = null; } } #endregion #region public methods /// /// Dispose of the class, close the file /// public void Dispose() { Close(); } /// /// Close the file /// public void Close() { if (m_writer != null) { m_writer.Flush(); m_writer.Close(); } } /// /// Log the message /// /// the message to log public override void LogMessage(UserMessage m) { if (m_writer != null) m_writer.WriteLine(m.ToString()); } #endregion } }