using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Logger
{
    public class XmlLogger
    {
        private StreamWriter f;
        private bool enable;
        /// <summary>
        /// Open log file and start loging session.
        /// </summary>
        /// <param name="file">path and file name.</param>
        public XmlLogger(string file)
        {
            string xmlHeader;
            string tmp;
            xmlHeader ="<?xml version=";
            xmlHeader +='"';
            xmlHeader +="1.0";
            xmlHeader +='"';
            xmlHeader +="?>";
            if (!File.Exists(file))
            {
                f = new StreamWriter(file, true);
                f.WriteLine(xmlHeader);
            }
            else
            {
                f = new StreamWriter(file, true);
            }
            tmp = "<LogSession Name=" + '"' + DateTime.Now.ToString() +'"'+ '>';
            f.WriteLine(tmp);
            enable = true;
        }
        
        /// <summary>
        /// closing log file.
        /// </summary>
        public void Close()
        {
            f.WriteLine("<Log Name=" + '"' + DateTime.Now.ToString() + '"' + '>' + "Closing log session </Log>");
            f.WriteLine("</LogSession>");
            f.Close();
        }
        
        /// <summary>
        /// Add message to log
        /// </summary>
        /// <param name="msg">message to add to log file.</param>
        public void Add(string msg)
        {
            if (enable)
            {
                f.WriteLine("<Log Name=" + '"' + DateTime.Now.ToString() + '"' + '>' + msg + "</Log>");
            }
        }
        
        /// <summary>
        /// Enable or disable the log capability.
        /// </summary>
        /// <param name="wantEnable">true if want to log.</param>
        public void EnableLog(bool wantEnable)
        {
            this.enable = wantEnable;
        }
        
    }
    public class Logger
    {
        private StreamWriter f;   // streaming file.
        private bool enable;
/// <summary>
/// Create log file object.
/// </summary>
/// <param name="file"></param>
        public Logger(string file)
        {
            f = new StreamWriter(file, true);
            f.WriteLine("<{0}> Starting logging", DateTime.Now);
            enable = true;
        }
        /// <summary>
        /// Close Log file.
        /// </summary>
        public void Close()
        {
            if (enable)
            {
                f.WriteLine("<{0}> Stop logging", DateTime.Now);
                f.WriteLine("*************************************************");
            }   
            f.Close();
        }
        
        /// <summary>
        /// Enable of disable logging process.
        /// </summary>
        /// <param name="wantEnable"></param>
        public void EnableLog(bool wantEnable)
        {
            this.enable = wantEnable;
        }

/// <summary>
/// Add Message to log file.
/// </summary>
/// <param name="msg">Message to write in log file.</param>
        public void Add(string msg)
        {
            if (enable)
                f.WriteLine("<{0}> {1}", DateTime.Now, msg);
        }
        
        
    }
}
