Example #1
0
		/// <summary>
		/// Create a new evaluator using the specified <see cref="Level"/> threshold.
		/// </summary>
		/// <param name="threshold">the threshold to trigger at</param>
		/// <remarks>
		/// <para>
		/// Create a new evaluator using the specified <see cref="Level"/> threshold.
		/// </para>
		/// <para>
		/// This evaluator will trigger if the level of the event
		/// passed to <see cref="IsTriggeringEvent(LoggingEvent)"/>
		/// is equal to or greater than the <see cref="Threshold"/>
		/// level.
		/// </para>
		/// </remarks>
		public LevelEvaluator(Level threshold) {
			if (threshold == null) {
				throw new ArgumentNullException("threshold");
			}

			m_threshold = threshold;
		}
Example #2
0
		/// <summary>
		/// Lookup the mapping for the specified level
		/// </summary>
		/// <param name="level">the level to lookup</param>
		/// <returns>the <see cref="LevelMappingEntry"/> for the level or <c>null</c> if no mapping found</returns>
		/// <remarks>
		/// <para>
		/// Lookup the value for the specified level. Finds the nearest
		/// mapping value for the level that is equal to or less than the
		/// <paramref name="level"/> specified.
		/// </para>
		/// <para>
		/// If no mapping could be found then <c>null</c> is returned.
		/// </para>
		/// </remarks>
		public LevelMappingEntry Lookup(Level level) {
			if (m_entries != null) {
				foreach (LevelMappingEntry entry in m_entries) {
					if (level >= entry.Level) {
						return entry;
					}
				}
			}
			return null;
		}
		/// <summary>
		/// Construct the repository using specific properties
		/// </summary>
		/// <param name="properties">the properties to set for this repository</param>
		/// <remarks>
		/// <para>
		/// Initializes the repository with specified properties.
		/// </para>
		/// </remarks>
		protected LoggerRepositorySkeleton(PropertiesDictionary properties) {
			m_properties = properties;
			m_rendererMap = new RendererMap();
			m_pluginMap = new PluginMap(this);
			m_levelMap = new LevelMap();
			m_configurationMessages = EmptyCollection.Instance;
			m_configured = false;

			AddBuiltinLevels();

			// Don't disable any levels by default.
			m_threshold = Level.All;
		}
Example #4
0
		/// <summary>
		/// Initializes a new instance of the <see cref="LoggingEvent" /> class
		/// from the supplied parameters.
		/// </summary>
		/// <param name="callerStackBoundaryDeclaringType">The declaring type of the method that is
		/// the stack boundary into the logging system for this call.</param>
		/// <param name="repository">The repository this event is logged in.</param>
		/// <param name="loggerName">The name of the logger of this event.</param>
		/// <param name="level">The level of this event.</param>
		/// <param name="message">The message of this event.</param>
		/// <param name="exception">The exception for this event.</param>
		/// <remarks>
		/// <para>
		/// Except <see cref="TimeStamp"/>, <see cref="Level"/> and <see cref="LoggerName"/>, 
		/// all fields of <c>LoggingEvent</c> are filled when actually needed. Call
		/// <see cref="FixVolatileData()"/> to cache all data locally
		/// to prevent inconsistencies.
		/// </para>
		/// <para>This method is called by the GodLesZ.Library.Logging framework
		/// to create a logging event.
		/// </para>
		/// </remarks>
		public LoggingEvent(Type callerStackBoundaryDeclaringType, GodLesZ.Library.Logging.Repository.ILoggerRepository repository, string loggerName, Level level, object message, Exception exception) {
			m_callerStackBoundaryDeclaringType = callerStackBoundaryDeclaringType;
			m_message = message;
			m_repository = repository;
			m_thrownException = exception;

			m_data.LoggerName = loggerName;
			m_data.Level = level;

			// Store the event creation time
			m_data.TimeStamp = DateTime.Now;
		}
Example #5
0
		/// <summary>
		/// Inserts an element into the <c>LevelCollection</c> at the specified index.
		/// </summary>
		/// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
		/// <param name="item">The <see cref="Level"/> to insert.</param>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero</para>
		/// <para>-or-</para>
		/// <para><paramref name="index"/> is equal to or greater than <see cref="LevelCollection.Count"/>.</para>
		/// </exception>
		public virtual void Insert(int index, Level item) {
			ValidateIndex(index, true); // throws

			if (m_count == m_array.Length) {
				EnsureCapacity(m_count + 1);
			}

			if (index < m_count) {
				Array.Copy(m_array, index, m_array, index + 1, m_count - index);
			}

			m_array[index] = item;
			m_count++;
			m_version++;
		}
Example #6
0
			public override int AddRange(Level[] x) {
				throw new NotSupportedException("This is a Read Only Collection and can not be modified");
			}
Example #7
0
		/// <summary>
		/// Lookup a named level from the map
		/// </summary>
		/// <param name="defaultLevel">the name of the level to lookup is taken from this level. 
		/// If the level is not set on the map then this level is added</param>
		/// <returns>the level in the map with the name specified</returns>
		/// <remarks>
		/// <para>
		/// Lookup a named level from the map. The name of the level to lookup is taken
		/// from the <see cref="Level.Name"/> property of the <paramref name="defaultLevel"/>
		/// argument.
		/// </para>
		/// <para>
		/// If no level with the specified name is found then the 
		/// <paramref name="defaultLevel"/> argument is added to the level map
		/// and returned.
		/// </para>
		/// </remarks>
		public Level LookupWithDefault(Level defaultLevel) {
			if (defaultLevel == null) {
				throw new ArgumentNullException("defaultLevel");
			}

			lock (this) {
				Level level = (Level)m_mapName2Level[defaultLevel.Name];
				if (level == null) {
					m_mapName2Level[defaultLevel.Name] = defaultLevel;
					return defaultLevel;
				}
				return level;
			}
		}
Example #8
0
			public override void CopyTo(Level[] array, int start) {
				m_collection.CopyTo(array, start);
			}
Example #9
0
			public override int IndexOf(Level x) {
				return m_collection.IndexOf(x);
			}
Example #10
0
		/// <summary>
		/// Construct a <see cref="RootLogger"/>
		/// </summary>
		/// <param name="level">The level to assign to the root logger.</param>
		/// <remarks>
		/// <para>
		/// Initializes a new instance of the <see cref="RootLogger" /> class with
		/// the specified logging level.
		/// </para>
		/// <para>
		/// The root logger names itself as "root". However, the root
		/// logger cannot be retrieved by name.
		/// </para>
		/// </remarks>
		public RootLogger(Level level)
			: base("root") {
			this.Level = level;
		}
Example #11
0
		/// <summary>
		/// Adds the elements of a <see cref="Level"/> array to the current <c>LevelCollection</c>.
		/// </summary>
		/// <param name="x">The <see cref="Level"/> array whose elements should be added to the end of the <c>LevelCollection</c>.</param>
		/// <returns>The new <see cref="LevelCollection.Count"/> of the <c>LevelCollection</c>.</returns>
		public virtual int AddRange(Level[] x) {
			if (m_count + x.Length >= m_array.Length) {
				EnsureCapacity(m_count + x.Length);
			}

			Array.Copy(x, 0, m_array, m_count, x.Length);
			m_count += x.Length;
			m_version++;

			return m_count;
		}
Example #12
0
		/// <summary>
		/// This is the most generic printing method. This generic form is intended to be used by wrappers
		/// </summary>
		/// <param name="level">The level of the message to be logged.</param>
		/// <param name="message">The message object to log.</param>
		/// <param name="exception">The exception to log, including its stack trace.</param>
		/// <remarks>
		/// <para>
		/// Generate a logging event for the specified <paramref name="level"/> using
		/// the <paramref name="message"/>.
		/// </para>
		/// </remarks>
		virtual public void Log(Level level, object message, Exception exception) {
			if (IsEnabledFor(level)) {
				ForcedLog(declaringType, level, message, exception);
			}
		}
Example #13
0
		/// <summary>
		/// Creates a new logging event and logs the event without further checks.
		/// </summary>
		/// <param name="callerStackBoundaryDeclaringType">The declaring type of the method that is
		/// the stack boundary into the logging system for this call.</param>
		/// <param name="level">The level of the message to be logged.</param>
		/// <param name="message">The message object to log.</param>
		/// <param name="exception">The exception to log, including its stack trace.</param>
		/// <remarks>
		/// <para>
		/// Generates a logging event and delivers it to the attached
		/// appenders.
		/// </para>
		/// </remarks>
		virtual protected void ForcedLog(Type callerStackBoundaryDeclaringType, Level level, object message, Exception exception) {
			CallAppenders(new LoggingEvent(callerStackBoundaryDeclaringType, this.Hierarchy, this.Name, level, message, exception));
		}
Example #14
0
		/// <summary>
		/// Checks if this logger is enabled for a given <see cref="Level"/> passed as parameter.
		/// </summary>
		/// <param name="level">The level to check.</param>
		/// <returns>
		/// <c>true</c> if this logger is enabled for <c>level</c>, otherwise <c>false</c>.
		/// </returns>
		/// <remarks>
		/// <para>
		/// Test if this logger is going to log events of the specified <paramref name="level"/>.
		/// </para>
		/// <para>
		/// This method must not throw any exception to the caller.
		/// </para>
		/// </remarks>
		virtual public bool IsEnabledFor(Level level) {
			try {
				if (level != null) {
					if (m_hierarchy.IsDisabled(level)) {
						return false;
					}
					return level >= this.EffectiveLevel;
				}
			} catch (Exception ex) {
				GodLesZ.Library.Logging.Util.LogLog.Error(declaringType, "Exception while logging", ex);
			}
#if !NET_2_0 && !MONO_2_0
			catch
			{
				GodLesZ.Library.Logging.Util.LogLog.Error(declaringType, "Exception while logging");
			}
#endif
			return false;
		}
Example #15
0
		/// <summary>
		/// This generic form is intended to be used by wrappers.
		/// </summary>
		/// <param name="callerStackBoundaryDeclaringType">The declaring type of the method that is
		/// the stack boundary into the logging system for this call.</param>
		/// <param name="level">The level of the message to be logged.</param>
		/// <param name="message">The message object to log.</param>
		/// <param name="exception">The exception to log, including its stack trace.</param>
		/// <remarks>
		/// <para>
		/// Generate a logging event for the specified <paramref name="level"/> using
		/// the <paramref name="message"/> and <paramref name="exception"/>.
		/// </para>
		/// <para>
		/// This method must not throw any exception to the caller.
		/// </para>
		/// </remarks>
		virtual public void Log(Type callerStackBoundaryDeclaringType, Level level, object message, Exception exception) {
			try {
				if (IsEnabledFor(level)) {
					ForcedLog((callerStackBoundaryDeclaringType != null) ? callerStackBoundaryDeclaringType : declaringType, level, message, exception);
				}
			} catch (Exception ex) {
				GodLesZ.Library.Logging.Util.LogLog.Error(declaringType, "Exception while logging", ex);
			}
#if !NET_2_0 && !MONO_2_0
			catch
			{
				GodLesZ.Library.Logging.Util.LogLog.Error(declaringType, "Exception while logging");
			}
#endif
		}
Example #16
0
		/// <summary>
		/// Initialize options
		/// </summary>
		/// <remarks>
		/// <para>
		/// Caches the sorted list of <see cref="LevelMappingEntry"/> in an array
		/// </para>
		/// </remarks>
		public void ActivateOptions() {
			Level[] sortKeys = new Level[m_entriesMap.Count];
			LevelMappingEntry[] sortValues = new LevelMappingEntry[m_entriesMap.Count];

			m_entriesMap.Keys.CopyTo(sortKeys, 0);
			m_entriesMap.Values.CopyTo(sortValues, 0);

			// Sort in level order
			Array.Sort(sortKeys, sortValues, 0, sortKeys.Length, null);

			// Reverse list so that highest level is first
			Array.Reverse(sortValues, 0, sortValues.Length);

			foreach (LevelMappingEntry entry in sortValues) {
				entry.ActivateOptions();
			}

			m_entries = sortValues;
		}
Example #17
0
		/// <summary>
		/// Removes the first occurrence of a specific <see cref="Level"/> from the <c>LevelCollection</c>.
		/// </summary>
		/// <param name="item">The <see cref="Level"/> to remove from the <c>LevelCollection</c>.</param>
		/// <exception cref="ArgumentException">
		/// The specified <see cref="Level"/> was not found in the <c>LevelCollection</c>.
		/// </exception>
		public virtual void Remove(Level item) {
			int i = IndexOf(item);
			if (i < 0) {
				throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");
			}

			++m_version;
			RemoveAt(i);
		}
Example #18
0
		/// <summary>
		/// Initializes a new instance of the <c>LevelCollection</c> class
		/// that contains elements copied from the specified <see cref="Level"/> array.
		/// </summary>
		/// <param name="a">The <see cref="Level"/> array whose elements are copied to the new list.</param>
		public LevelCollection(Level[] a) {
			m_array = new Level[a.Length];
			AddRange(a);
		}
Example #19
0
		/// <summary>
		/// Removes the element at the specified index of the <c>LevelCollection</c>.
		/// </summary>
		/// <param name="index">The zero-based index of the element to remove.</param>
		/// <exception cref="ArgumentOutOfRangeException">
		/// <para><paramref name="index"/> is less than zero</para>
		/// <para>-or-</para>
		/// <para><paramref name="index"/> is equal to or greater than <see cref="LevelCollection.Count"/>.</para>
		/// </exception>
		public virtual void RemoveAt(int index) {
			ValidateIndex(index); // throws

			m_count--;

			if (index < m_count) {
				Array.Copy(m_array, index + 1, m_array, index, m_count - index);
			}

			// We can't set the deleted entry equal to null, because it might be a value type.
			// Instead, we'll create an empty single-element array of the right type and copy it 
			// over the entry we want to erase.
			Level[] temp = new Level[1];
			Array.Copy(temp, 0, m_array, m_count, 1);
			m_version++;
		}
Example #20
0
		/// <summary>
		/// Copies the entire <c>LevelCollection</c> to a one-dimensional
		/// <see cref="Level"/> array.
		/// </summary>
		/// <param name="array">The one-dimensional <see cref="Level"/> array to copy to.</param>
		public virtual void CopyTo(Level[] array) {
			this.CopyTo(array, 0);
		}
Example #21
0
			public override void CopyTo(Level[] array) {
				m_collection.CopyTo(array);
			}
Example #22
0
		/// <summary>
		/// Copies the entire <c>LevelCollection</c> to a one-dimensional
		/// <see cref="Level"/> array, starting at the specified index of the target array.
		/// </summary>
		/// <param name="array">The one-dimensional <see cref="Level"/> array to copy to.</param>
		/// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param>
		public virtual void CopyTo(Level[] array, int start) {
			if (m_count > array.GetUpperBound(0) + 1 - start) {
				throw new System.ArgumentException("Destination array was not long enough.");
			}

			Array.Copy(m_array, 0, array, start, m_count);
		}
Example #23
0
			public override bool Contains(Level x) {
				return m_collection.Contains(x);
			}
Example #24
0
		/// <summary>
		/// Adds a <see cref="Level"/> to the end of the <c>LevelCollection</c>.
		/// </summary>
		/// <param name="item">The <see cref="Level"/> to be added to the end of the <c>LevelCollection</c>.</param>
		/// <returns>The index at which the value has been added.</returns>
		public virtual int Add(Level item) {
			if (m_count == m_array.Length) {
				EnsureCapacity(m_count + 1);
			}

			m_array[m_count] = item;
			m_version++;

			return m_count++;
		}
Example #25
0
			public override void Remove(Level x) {
				throw new NotSupportedException("This is a Read Only Collection and can not be modified");
			}
Example #26
0
		/// <summary>
		/// Checks if the message level is below this appender's threshold.
		/// </summary>
		/// <param name="level"><see cref="Level"/> to test against.</param>
		/// <remarks>
		/// <para>
		/// If there is no threshold set, then the return value is always <c>true</c>.
		/// </para>
		/// </remarks>
		/// <returns>
		/// <c>true</c> if the <paramref name="level"/> meets the <see cref="Threshold"/> 
		/// requirements of this appender.
		/// </returns>
		virtual protected bool IsAsSevereAsThreshold(Level level) {
			return ((m_threshold == null) || level >= m_threshold);
		}
Example #27
0
		/// <summary>
		/// Add a Level to the map
		/// </summary>
		/// <param name="level">the Level to add</param>
		/// <remarks>
		/// <para>
		/// Add a Level to the map
		/// </para>
		/// </remarks>
		public void Add(Level level) {
			if (level == null) {
				throw new ArgumentNullException("level");
			}
			lock (this) {
				m_mapName2Level[level.Name] = level;
			}
		}
Example #28
0
		/// <summary>
		/// Returns the zero-based index of the first occurrence of a <see cref="Level"/>
		/// in the <c>LevelCollection</c>.
		/// </summary>
		/// <param name="item">The <see cref="Level"/> to locate in the <c>LevelCollection</c>.</param>
		/// <returns>
		/// The zero-based index of the first occurrence of <paramref name="item"/> 
		/// in the entire <c>LevelCollection</c>, if found; otherwise, -1.
		///	</returns>
		public virtual int IndexOf(Level item) {
			for (int i = 0; i != m_count; ++i) {
				if (m_array[i].Equals(item)) {
					return i;
				}
			}
			return -1;
		}
Example #29
0
		/// <summary>
		/// Determines whether a given <see cref="Level"/> is in the <c>LevelCollection</c>.
		/// </summary>
		/// <param name="item">The <see cref="Level"/> to check for.</param>
		/// <returns><c>true</c> if <paramref name="item"/> is found in the <c>LevelCollection</c>; otherwise, <c>false</c>.</returns>
		public virtual bool Contains(Level item) {
			for (int i = 0; i != m_count; ++i) {
				if (m_array[i].Equals(item)) {
					return true;
				}
			}
			return false;
		}
Example #30
0
		/// <summary>
		/// Get the equivalent <see cref="EventLogEntryType"/> for a <see cref="Level"/> <paramref name="level"/>
		/// </summary>
		/// <param name="level">the Level to convert to an EventLogEntryType</param>
		/// <returns>The equivalent <see cref="EventLogEntryType"/> for a <see cref="Level"/> <paramref name="level"/></returns>
		/// <remarks>
		/// Because there are fewer applicable <see cref="EventLogEntryType"/>
		/// values to use in logging levels than there are in the 
		/// <see cref="Level"/> this is a one way mapping. There is
		/// a loss of information during the conversion.
		/// </remarks>
		virtual protected EventLogEntryType GetEntryType(Level level) {
			// see if there is a specified lookup.
			Level2EventLogEntryType entryType = m_levelMapping.Lookup(level) as Level2EventLogEntryType;
			if (entryType != null) {
				return entryType.EventLogEntryType;
			}

			// Use default behavior

			if (level >= Level.Error) {
				return EventLogEntryType.Error;
			} else if (level == Level.Warn) {
				return EventLogEntryType.Warning;
			}

			// Default setting
			return EventLogEntryType.Information;
		}