/// <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="M: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; }
/// <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) { Mammothcode.Public.Core.Util.LogLog.Error(declaringType, "Exception while logging", ex); } #if NETCF catch { Mammothcode.Public.Core.Util.LogLog.Error(declaringType, "Exception while logging"); } #endif }
/// <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> /// 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; } }
/// <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; }
/// <summary> /// Compares two specified <see cref="Level"/> instances. /// </summary> /// <param name="l">The first <see cref="Level"/> to compare.</param> /// <param name="r">The second <see cref="Level"/> to compare.</param> /// <returns> /// A 32-bit signed integer that indicates the relative order of the /// two values compared. The return value has these meanings: /// <list type="table"> /// <listheader> /// <term>Value</term> /// <description>Meaning</description> /// </listheader> /// <item> /// <term>Less than zero</term> /// <description><paramref name="l" /> is less than <paramref name="r" />.</description> /// </item> /// <item> /// <term>Zero</term> /// <description><paramref name="l" /> is equal to <paramref name="r" />.</description> /// </item> /// <item> /// <term>Greater than zero</term> /// <description><paramref name="l" /> is greater than <paramref name="r" />.</description> /// </item> /// </list> /// </returns> /// <remarks> /// <para> /// Compares two levels. /// </para> /// </remarks> public static int Compare(Level l, Level r) { // Reference equals if ((object)l == (object)r) { return 0; } if (l == null && r == null) { return 0; } if (l == null) { return -1; } if (r == null) { return 1; } return l.m_levelValue.CompareTo(r.m_levelValue); }
public override int AddRange(Level[] x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
public override int IndexOf(Level x) { return m_collection.IndexOf(x); }
/// <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++; }
/// <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); }
/// <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); }
/// <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); }
/// <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)); }
/// <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); } }
/// <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) { Mammothcode.Public.Core.Util.LogLog.Error(declaringType, "Exception while logging", ex); } #if NETCF catch { Mammothcode.Public.Core.Util.LogLog.Error(declaringType, "Exception while logging"); } #endif return false; }
public override void CopyTo(Level[] array, int start) { m_collection.CopyTo(array,start); }
public override bool Contains(Level x) { return m_collection.Contains(x); }
/// <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; }
public override void Remove(Level x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
/// <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; }
/// <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); }
/// <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++; }
/// <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; }
/// <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); }
/// <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; } }
/// <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++; }
/// <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; }
/// <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; }
public override void CopyTo(Level[] array) { m_collection.CopyTo(array); }
/// <summary> /// Translates a log4net level to a syslog severity. /// </summary> /// <param name="level">A log4net level.</param> /// <returns>A syslog severity.</returns> /// <remarks> /// <para> /// Translates a log4net level to a syslog severity. /// </para> /// </remarks> virtual protected SyslogSeverity GetSeverity(Level level) { LevelSeverity levelSeverity = m_levelMapping.Lookup(level) as LevelSeverity; if (levelSeverity != null) { return levelSeverity.Severity; } // // Fallback to sensible default values // if (level >= Level.Alert) { return SyslogSeverity.Alert; } else if (level >= Level.Critical) { return SyslogSeverity.Critical; } else if (level >= Level.Error) { return SyslogSeverity.Error; } else if (level >= Level.Warn) { return SyslogSeverity.Warning; } else if (level >= Level.Notice) { return SyslogSeverity.Notice; } else if (level >= Level.Info) { return SyslogSeverity.Informational; } // Default setting return SyslogSeverity.Debug; }