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

namespace WindowsApplication1
{
    class logger
    {
        StreamWriter sw;
        DateTime date = new DateTime();
        RichTextBox textbox;
        bool tofile = true;

        // konstruktor
        public logger(RichTextBox atextbox) {
            try
            {
                sw = new StreamWriter("log.txt", true);
            }
            catch
            {
                tofile = false;
            }
            textbox = atextbox;
            textbox.Clear();
            add(2, "Configurator executed");
           
        }

        // vypise log do textboxu a do souboru
        public void add(int atype, string atext){
            date = DateTime.Now;
            string sErr, sOut;
            switch (atype){
                case 0: sErr = "[OK]"; break;
                case 1: sErr = "[ERROR]"; break;
                case 3: sErr = "[DEVICE]"; break;
                default: sErr = "[INFO]"; break;
            }
            sOut = date.ToString() + " " + sErr + " " + atext;
            textbox.AppendText(sOut+"\n");
            textbox.ScrollToCaret();
            if (tofile)
            {
                sw.WriteLine(sOut);
                sw.Flush();
            }
        }

    }
}
