This project is read-only.

EventLogName

The EventLogName class is used to make the set of available string event log names a closed set:

/// <summary>
/// Event log names for available event logs in Windows Azure. This provides a type safe implementation of the possible event logs.
/// </summary>
public sealed class EventLogName : IEquatable<EventLogName>
{
	/// <summary>
	/// Write to the Information event log
	/// </summary>
	public static EventLogName Information = new EventLogName("Information");

	/// <summary>
	/// Write to the Warning event log
	/// </summary>
	public static EventLogName Warning = new EventLogName("Warning");

	/// <summary>
	/// Write to the Verbose event log
	/// </summary>
	public static EventLogName Verbose = new EventLogName("Verbose");

	/// <summary>
	/// Write to the Error event log
	/// </summary>
	public static EventLogName Error = new EventLogName("Error");

	/// <summary>
	/// Log entries marked with the Critical designation are also raised as alerts to the service via the alerting interface. 
	/// Because these alerts must be reviewed by an operator, Critical messages should be used only for urgent notifications.
	/// </summary>
	public static EventLogName Critical = new EventLogName("Critical");

	private readonly string eventLogName;

	private EventLogName(string eventLogName)
	{
		this.eventLogName = eventLogName;
	}

	/// <summary>
	/// The <see cref="EventLogName"/> as a string
	/// </summary>
	/// <returns>a string</returns>
	public override string ToString()
	{
		return eventLogName;
	}

	/// <summary>
	/// Convert an <see cref="EventLogName"/> to a <see cref="string"/>
	/// </summary>
	/// <param name="eventLogName">To convert</param>
	/// <returns>the <see cref="EventLogName"/> as a <see cref="string"/></returns>
	public static implicit operator string(EventLogName eventLogName)
	{
		return eventLogName.ToString();
	}

	/// <summary>
	/// Enumerate all the <see cref="eventLogName"/>s
	/// </summary>
	/// <returns>The available event log names</returns>
	public static IEnumerable<EventLogName> EventLogNames
	{
		get
		{
			return (from field in typeof(EventLogName).GetFields()
							where field.FieldType == typeof(EventLogName)
							select (EventLogName)field.GetValue(null));
		}
	}

	/// <summary>
	/// Equality between two <see cref="EventLogName"/>
	/// </summary>
	/// <param name="other">The other one to compare with.</param>
	/// <returns>True if the <see cref="EventLogName"/>s are equal</returns>
	public bool Equals(EventLogName other)
	{
		return ToString() == other.ToString();
	}

	/// <summary>
	/// Equality between an <see cref="object"/> and an <see cref="EventLogName"/>
	/// </summary>
	/// <param name="obj">The <see cref="object"/> to compare with.</param>
	/// <returns>True if the <see cref="object"/> and the <see cref="EventLogName"/>are equal</returns>
	public override bool Equals(object obj)
	{
		EventLogName o = obj as EventLogName;
		return o != null && Equals(o);
	}

	/// <summary>
	/// The hash code for an <see cref="EventLogName"/> is the hash code value of it's name
	/// </summary>
	/// <returns>The hash code</returns>
	public override int GetHashCode()
	{
		return ToString().GetHashCode();
	}
}

Last edited Aug 24, 2009 at 10:10 AM by NoopMan, version 1

Comments

No comments yet.