/// <summary>
		/// Set the next converter in the chain
		/// </summary>
		/// <param name="pc">The next pattern converter in the chain</param>
		/// <returns>The next pattern converter</returns>
		/// <remarks>
		/// <para>
		/// Special case the building of the pattern converter chain
		/// for <see cref="LiteralPatternConverter"/> instances. Two adjacent
		/// literals in the pattern can be represented by a single combined
		/// pattern converter. This implementation detects when a 
		/// <see cref="LiteralPatternConverter"/> is added to the chain
		/// after this converter and combines its value with this converter's
		/// literal value.
		/// </para>
		/// </remarks>
		public override PatternConverter SetNext(PatternConverter pc) {
			LiteralPatternConverter literalPc = pc as LiteralPatternConverter;
			if (literalPc != null) {
				// Combine the two adjacent literals together
				Option = Option + literalPc.Option;

				// We are the next converter now
				return this;
			}

			return base.SetNext(pc);
		}
Example #2
0
        /// <summary>
        /// Produces a formatted string as specified by the conversion pattern.
        /// </summary>
        /// <param name="writer">The TextWriter to write the formatted event to</param>
        /// <remarks>
        /// <para>
        /// Format the pattern to the <paramref name="writer"/>.
        /// </para>
        /// </remarks>
        public void Format(TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            PatternConverter c = m_head;

            // loop through the chain of pattern converters
            while (c != null)
            {
                c.Format(writer, null);
                c = c.Next;
            }
        }
Example #3
0
        /// <summary>
        /// Resets the internal state of the parser and adds the specified pattern converter
        /// to the chain.
        /// </summary>
        /// <param name="pc">The pattern converter to add.</param>
        private void AddConverter(PatternConverter pc)
        {
            // Add the pattern converter to the list.

            if (m_head == null)
            {
                m_head = m_tail = pc;
            }
            else
            {
                // Set the next converter on the tail
                // Update the tail reference
                // note that a converter may combine the 'next' into itself
                // and therefore the tail would not change!
                m_tail = m_tail.SetNext(pc);
            }
        }
Example #4
0
        /// <summary>
        /// Process a parsed converter pattern
        /// </summary>
        /// <param name="converterName">the name of the converter</param>
        /// <param name="option">the optional option for the converter</param>
        /// <param name="formattingInfo">the formatting info for the converter</param>
        private void ProcessConverter(string converterName, string option, FormattingInfo formattingInfo)
        {
            LogLog.Debug(declaringType, "Converter [" + converterName + "] Option [" + option + "] Format [min=" + formattingInfo.Min + ",max=" + formattingInfo.Max + ",leftAlign=" + formattingInfo.LeftAlign + "]");

            // Lookup the converter type
            ConverterInfo converterInfo = (ConverterInfo)m_patternConverters[converterName];

            if (converterInfo == null)
            {
                LogLog.Error(declaringType, "Unknown converter name [" + converterName + "] in conversion pattern.");
            }
            else
            {
                // Create the pattern converter
                PatternConverter pc = null;
                try {
                    pc = (PatternConverter)Activator.CreateInstance(converterInfo.Type);
                } catch (Exception createInstanceEx) {
                    LogLog.Error(declaringType, "Failed to create instance of Type [" + converterInfo.Type.FullName + "] using default constructor. Exception: " + createInstanceEx.ToString());
                }

                // formattingInfo variable is an instance variable, occasionally reset
                // and used over and over again
                pc.FormattingInfo = formattingInfo;
                pc.Option         = option;
                pc.Properties     = converterInfo.Properties;

                IOptionHandler optionHandler = pc as IOptionHandler;
                if (optionHandler != null)
                {
                    optionHandler.ActivateOptions();
                }

                AddConverter(pc);
            }
        }
Example #5
0
		/// <summary>
		/// Set the next pattern converter in the chains
		/// </summary>
		/// <param name="patternConverter">the pattern converter that should follow this converter in the chain</param>
		/// <returns>the next converter</returns>
		/// <remarks>
		/// <para>
		/// The PatternConverter can merge with its neighbor during this method (or a sub class).
		/// Therefore the return value may or may not be the value of the argument passed in.
		/// </para>
		/// </remarks>
		public virtual PatternConverter SetNext(PatternConverter patternConverter) {
			m_next = patternConverter;
			return m_next;
		}
Example #6
0
 /// <summary>
 /// Initialize object options
 /// </summary>
 /// <remarks>
 /// <para>
 /// This is part of the <see cref="IOptionHandler"/> delayed object
 /// activation scheme. The <see cref="ActivateOptions"/> method must
 /// be called on this object after the configuration properties have
 /// been set. Until <see cref="ActivateOptions"/> is called this
 /// object is in an undefined state and must not be used.
 /// </para>
 /// <para>
 /// If any of the configuration properties are modified then
 /// <see cref="ActivateOptions"/> must be called again.
 /// </para>
 /// </remarks>
 virtual public void ActivateOptions()
 {
     m_head = CreatePatternParser(m_pattern).Parse();
 }
Example #7
0
		/// <summary>
		/// Initialize layout options
		/// </summary>
		/// <remarks>
		/// <para>
		/// This is part of the <see cref="IOptionHandler"/> delayed object
		/// activation scheme. The <see cref="ActivateOptions"/> method must 
		/// be called on this object after the configuration properties have
		/// been set. Until <see cref="ActivateOptions"/> is called this
		/// object is in an undefined state and must not be used. 
		/// </para>
		/// <para>
		/// If any of the configuration properties are modified then 
		/// <see cref="ActivateOptions"/> must be called again.
		/// </para>
		/// </remarks>
		override public void ActivateOptions() {
			m_head = CreatePatternParser(m_pattern).Parse();

			PatternConverter curConverter = m_head;
			while (curConverter != null) {
				PatternLayoutConverter layoutConverter = curConverter as PatternLayoutConverter;
				if (layoutConverter != null) {
					if (!layoutConverter.IgnoresException) {
						// Found converter that handles the exception
						this.IgnoresException = false;

						break;
					}
				}
				curConverter = curConverter.Next;
			}
		}
Example #8
0
		/// <summary>
		/// Initialize object options
		/// </summary>
		/// <remarks>
		/// <para>
		/// This is part of the <see cref="IOptionHandler"/> delayed object
		/// activation scheme. The <see cref="ActivateOptions"/> method must 
		/// be called on this object after the configuration properties have
		/// been set. Until <see cref="ActivateOptions"/> is called this
		/// object is in an undefined state and must not be used. 
		/// </para>
		/// <para>
		/// If any of the configuration properties are modified then 
		/// <see cref="ActivateOptions"/> must be called again.
		/// </para>
		/// </remarks>
		virtual public void ActivateOptions() {
			m_head = CreatePatternParser(m_pattern).Parse();
		}
Example #9
0
		/// <summary>
		/// Resets the internal state of the parser and adds the specified pattern converter 
		/// to the chain.
		/// </summary>
		/// <param name="pc">The pattern converter to add.</param>
		private void AddConverter(PatternConverter pc) {
			// Add the pattern converter to the list.

			if (m_head == null) {
				m_head = m_tail = pc;
			} else {
				// Set the next converter on the tail
				// Update the tail reference
				// note that a converter may combine the 'next' into itself
				// and therefore the tail would not change!
				m_tail = m_tail.SetNext(pc);
			}
		}
Example #10
0
 /// <summary>
 /// Set the next pattern converter in the chains
 /// </summary>
 /// <param name="patternConverter">the pattern converter that should follow this converter in the chain</param>
 /// <returns>the next converter</returns>
 /// <remarks>
 /// <para>
 /// The PatternConverter can merge with its neighbor during this method (or a sub class).
 /// Therefore the return value may or may not be the value of the argument passed in.
 /// </para>
 /// </remarks>
 public virtual PatternConverter SetNext(PatternConverter patternConverter)
 {
     m_next = patternConverter;
     return(m_next);
 }