Skip to content
/ NLog Public template
forked from NLog/NLog
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and docs #8

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/NLog/Internal/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ namespace NLog.Internal
{
internal static class CollectionExtensions
{
public static IList<TItem> FilterList<TItem,TState>([NotNull] this IList<TItem> items, TState state, Func<TItem, TState, bool> filter)
/// <summary>
/// Memory optimized filtering
/// </summary>
[NotNull]
public static IList<TItem> Filter<TItem>([NotNull] this IList<TItem> items, Func<TItem, bool> filter)
{
var hasIgnoredLogEvents = false;
IList<TItem> filterLogEvents = null;
for (var i = 0; i < items.Count; ++i)
{
var item = items[i];
if (filter(item, state))
if (filter(item))
{
if (hasIgnoredLogEvents && filterLogEvents == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Targets/Wrappers/FilteringTargetWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected override void Write(AsyncLogEventInfo logEvent)
/// <inheritdoc/>
protected override void Write(IList<AsyncLogEventInfo> logEvents)
{
var filterLogEvents = logEvents.FilterList(Filter, ShouldLogEvent);
var filterLogEvents = logEvents.Filter(logEvent => ShouldLogEvent(logEvent, Filter));
WrappedTarget.WriteAsyncLogEvents(filterLogEvents);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Targets/Wrappers/PostFilteringTargetWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected override void Write(IList<AsyncLogEventInfo> logEvents)
else
{
InternalLogger.Trace("PostFilteringWrapper(Name={0}): Filter to apply: {1}", Name, resultFilter);
var resultBuffer = logEvents.FilterList(resultFilter, ApplyFilter);
var resultBuffer = logEvents.Filter(logEvent => ApplyFilter(logEvent, resultFilter));
InternalLogger.Trace("PostFilteringWrapper(Name={0}): After filtering: {1} events.", Name, resultBuffer.Count);
if (resultBuffer.Count > 0)
{
Expand Down