コード例 #1
0
			/// <summary>
			/// To the conversion
			/// </summary>
			/// <param name="loggingEvent">the event being logged</param>
			/// <returns>the result of converting the pattern</returns>
			override protected string Convert(LoggingEvent loggingEvent) 
			{
				return loggingEvent.LookupMappedContext(m_key);
			}
コード例 #2
0
		/// <summary>
		/// Check if this filter should allow the event to be logged
		/// </summary>
		/// <remarks>
		/// The <see cref="MDC"/> is matched against the <see cref="StringToMatch"/>.
		/// If the <see cref="StringToMatch"/> occurs as a substring within
		/// the message then a match will have occurred. If no match occurs
		/// this function will return <see cref="FilterDecision.NEUTRAL"/>
		/// allowing other filters to check the event. If a match occurs then
		/// the value of <see cref="AcceptOnMatch"/> is checked. If it is
		/// true then <see cref="FilterDecision.ACCEPT"/> is returned otherwise
		/// <see cref="FilterDecision.DENY"/> is returned.
		/// </remarks>
		/// <param name="loggingEvent">the event being logged</param>
		/// <returns>see remarks</returns>
		override public FilterDecision Decide(LoggingEvent loggingEvent) 
		{
			if (loggingEvent == null)
			{
				throw new ArgumentNullException("loggingEvent");
			}

			// Check if we have a key to lookup the MDC value with
			if (m_key == null)
			{
				// We cannot filter so allow the filter chain
				// to continue processing
				return FilterDecision.NEUTRAL;
			}

			// Lookup the string to match in from the MDC using 
			// the key specified.
			string msg = loggingEvent.LookupMappedContext(m_key);

			// Check if we have been setup to filter
			if (msg == null || (m_stringToMatch == null && m_regexToMatch == null))
			{
				// We cannot filter so allow the filter chain
				// to continue processing
				return FilterDecision.NEUTRAL;
			}
    
			// Firstly check if we are matching using a regex
			if (m_regexToMatch != null)
			{
				// Check the regex
				if (m_regexToMatch.Match(msg).Success == false)
				{
					// No match, continue processing
					return FilterDecision.NEUTRAL;
				} 

				// we've got a match
				if (m_acceptOnMatch) 
				{
					return FilterDecision.ACCEPT;
				} 
				return FilterDecision.DENY;
			}
			else if (m_stringToMatch != null)
			{
				// Check substring match
				if (msg.IndexOf(m_stringToMatch) == -1) 
				{
					// No match, continue processing
					return FilterDecision.NEUTRAL;
				} 

				// we've got a match
				if (m_acceptOnMatch) 
				{
					return FilterDecision.ACCEPT;
				} 
				return FilterDecision.DENY;
			}
			return FilterDecision.NEUTRAL;
		}