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

namespace CDAValidator
{
    class Logging
    {

        private static string sLogFile = ConfigSettings.Default.LogFilePath + @"\CDAValidator.log";
        //private static string sLogFile = @"C:\casmed\CDALetters\CDAValidator.log";

        /// <summary>
        /// will store eventlog to Windows Application Event Log
        /// </summary>
        /// <param name="message">Log message</param>
        /// <param name="type">type [Error, Information, Warning, .... ]</param>
        static public void eventLog(string message, EventLogEntryType type)
        {
            System.Diagnostics.EventLog l = new System.Diagnostics.EventLog();
            l.Source = "CDAValidator";
            l.WriteEntry(message, type);
        }


        static public void eventLog(Exception ex)
        {
            string s = ex.Message + "\n" + ex.StackTrace;
            eventLog(s, EventLogEntryType.Error);
        }


        static public void writeLog(string Message)
        {
            if (!File.Exists(sLogFile))
            {
                File.Create(sLogFile);
            }

            StreamWriter writer = File.AppendText(sLogFile);
            writer.WriteLine(DateTime.Now.ToString("dd/MM/yyyy H:mm") + " " + Message);
            writer.Close();
        }


    }
}
