Esempio n. 1
0
        /// <summary>
        /// Repeated LogEvent detected. Checks if it should activate filter-action
        /// </summary>
        FilterResult RefreshFilterInfo(LogEventInfo logEvent, FilterInfo filterInfo)
        {
            if (filterInfo.HasExpired(logEvent.TimeStamp, TimeoutSeconds) || logEvent.Level.Ordinal > filterInfo.LogLevel.Ordinal)
            {
                int filterCount = filterInfo.FilterCount;
                if (filterCount > 0 && filterInfo.IsObsolete(logEvent.TimeStamp, TimeoutSeconds))
                {
                    filterCount = 0;
                }

                filterInfo.Refresh(logEvent.Level, logEvent.TimeStamp, 0);

                if (filterCount > 0)
                {
                    if (!string.IsNullOrEmpty(FilterCountPropertyName))
                    {
                        object otherFilterCount;
                        if (!logEvent.Properties.TryGetValue(FilterCountPropertyName, out otherFilterCount))
                        {
                            logEvent.Properties[FilterCountPropertyName] = filterCount;
                        }
                        else if (otherFilterCount is int)
                        {
                            filterCount = Math.Max((int)otherFilterCount, filterCount);
                            logEvent.Properties[FilterCountPropertyName] = filterCount;
                        }
                    }
                    if (!string.IsNullOrEmpty(FilterCountMessageAppendFormat))
                    {
                        if (logEvent.Message != null)
                        {
                            logEvent.Message += string.Format(FilterCountMessageAppendFormat, filterCount.ToString(System.Globalization.CultureInfo.InvariantCulture));
                        }
                    }
                }

                return(FilterResult.Neutral);
            }
            else
            {
                filterInfo.Refresh(logEvent.Level, logEvent.TimeStamp, filterInfo.FilterCount + 1);
                return(Action);
            }
        }