using System;
using System.Diagnostics;

namespace Minntech.Logging
{
	public interface ILogProvider : IDisposable
	{
		void Initialize ();
		void WriteLog	( string Text );
		void WriteLog	( string Text, EventLogEntryType LogType );
		void WriteLog	( string Text, EventLogEntryType LogType, byte[] Data );
	}

	/// <summary>
	/// Summary description for Log.
	/// </summary>
	public class Log : IDisposable
	{
		private		   ILogProvider	_provider = null;
		private static Log			_instance = null;

		#region construct/init/dispose

		private Log()
		{
		}

		public static Log GetInstance()
		{
			if ( _instance == null )
				_instance = new Log();
			return _instance;
		}
		public void Dispose()
		{
			this._provider.Dispose();
		}

		#endregion
		
		public ILogProvider Provider 
		{
			get { return this._provider;  }
			set { this._provider = value; }
		}


		public bool WriteLog(string Text)
		{
			return this.WriteLog ( Text, EventLogEntryType.Information, null );
		}
		public bool WriteLog(string Text, EventLogEntryType LogEntryType )
		{
			return this.WriteLog ( Text, LogEntryType, null );
		}
		public bool WriteLog(string Text, EventLogEntryType LogEntryType, byte[] Data )
		{
			bool rtnVal = true;
			try
			{
				this._provider.WriteLog ( Text, LogEntryType, Data );
			}
			catch 
			{
				// cannot raise exception here, this method
				// is commonly used by error handlers
				rtnVal = false;
			}
			return rtnVal;
		}
	}
}
