Return to Snippet

Revision: 49758
at July 29, 2011 08:25 by BrentS


Initial Code
using System;

namespace Median.Omnia.ServiceHost
{
	using System.Diagnostics;

	public interface ILogger 
	{
		void Debug(string text);
		void Warn(string text);
		void Error(string text);
		void Error(string text, Exception ex);
	}

	public class EventLogger : ILogger
	{
		public void Debug(string text)
		{
			CheckSourceExists();
			EventLog.WriteEntry("MedianService", text, EventLogEntryType.Information);
		}

		public void Warn(string text)
		{
			CheckSourceExists();
			EventLog.WriteEntry("MedianService", text, EventLogEntryType.Warning);
		}

		public void Error(string text)
		{
			CheckSourceExists();
			EventLog.WriteEntry("MedianService", text, EventLogEntryType.Error);
		}

		public void Error(string text, Exception ex)
		{
			CheckSourceExists();
			Error(text);
			Error(ex.StackTrace);
		}

		private static void CheckSourceExists()
		{
			if (!EventLog.SourceExists("MedianService"))
			{
				EventLog.CreateEventSource("MedianService", "Application");
			}
		}
	}
}

Initial URL


Initial Description


Initial Title
EventLoggingInterface

Initial Tags
event, log, c#

Initial Language
C#