view Logging/LogNotifier.cs @ 0:961030992bd2

Initial commit of IBBoard libraries
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 11:13:48 +0000
parents
children 465b672e9682
line wrap: on
line source

// LogNotifier.cs
//
//  Copyright (C) 2008 IBBoard
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
//
//

using System;

namespace IBBoard.Logging
{
	public delegate void LogEventOccurredDelegate(Type logFromType, Object message, Exception e);	
	
	public class LogNotifier
	{
		public static event LogEventOccurredDelegate DebugLogEventOccurred;
		public static event LogEventOccurredDelegate InfoLogEventOccurred;
		public static event LogEventOccurredDelegate WarningLogEventOccurred;
		public static event LogEventOccurredDelegate ErrorLogEventOccurred;
		public static event LogEventOccurredDelegate FatalLogEventOccurred;
		
		public static void DebugFormat(Type logFromType, String message, params object[] vals)
		{
			Debug(logFromType, String.Format(message, vals));
		}
		
		public static void Debug(Type logFromType, Object message)
		{
			Debug(logFromType, message, null);
		}
		
		public static void Debug(Type logFromType, Object message, Exception e)
		{
			if (DebugLogEventOccurred!=null)
			{
				DebugLogEventOccurred(logFromType, message, e);
			}
		}
		
		public static void InfoFormat(Type logFromType, String message, params object[] vals)
		{
			Info(logFromType, String.Format(message, vals));
		}
		
		public static void Info(Type logFromType, Object message)
		{
			Info(logFromType, message, null);
		}
		
		public static void Info(Type logFromType, Object message, Exception e)
		{
			Console.WriteLine("Info:  "+(InfoLogEventOccurred!=null ? "true":"false")+" "+message);
			if (InfoLogEventOccurred!=null)
			{
				InfoLogEventOccurred(logFromType, message, e);
			}
		}
		
		public static void WarnFormat(Type logFromType, String message, params object[] vals)
		{
			Warn(logFromType, String.Format(message, vals));
		}
		
		public static void Warn(Type logFromType, Object message)
		{
			Warn(logFromType, message, null);
		}
		
		public static void Warn(Type logFromType, Object message, Exception e)
		{
			if (WarningLogEventOccurred!=null)
			{
				WarningLogEventOccurred(logFromType, message, e);
			}
		}
		
		public static void ErrorFormat(Type logFromType, String message, params object[] vals)
		{
			Error(logFromType, String.Format(message, vals));
		}
		
		public static void Error(Type logFromType, Object message)
		{
			Error(logFromType, message, null);
		}
		
		public static void Error(Type logFromType, Object message, Exception e)
		{
			if (ErrorLogEventOccurred!=null)
			{
				ErrorLogEventOccurred(logFromType, message, e);
			}
		}
		
		public static void FatalFormat(Type logFromType, String message, params object[] vals)
		{
			Fatal(logFromType, String.Format(message, vals));
		}
		
		public static void Fatal(Type logFromType, Object message)
		{
			Fatal(logFromType, message, null);
		}
		
		public static void Fatal(Type logFromType, Object message, Exception e)
		{
			if (FatalLogEventOccurred!=null)
			{
				FatalLogEventOccurred(logFromType, message, e);
			}
		}
	}
}