Skip to content

Commit

Permalink
解决先包含再任一的过滤错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
walterlv committed Aug 20, 2024
1 parent 43d82ef commit bceacc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/dotnetCampus.Logger/Writers/Helpers/TagFilterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,16 @@ internal bool IsTagEnabled(string text)
}
// 如果有任一标签,则匹配一个即可。
满足 =满足 || AnyFilterTags.Contains(tag);
if (任一满足)
// 如果有包含标签,则匹配一个,直到全部匹配。
if (!包含满足 && IncludingFilterTags.Count > 0)
{
// 如果有包含标签,则匹配一个,直到全部匹配。
if (!包含满足 && IncludingFilterTags.Count > 0)
if (includingTags.Contains(tag))
{
if (includingTags.Contains(tag))
{
includingTags.Remove(tag);
}
if (includingTags.Count is 0)
{
包含满足 = true;
}
includingTags.Remove(tag);
}
if (includingTags.Count is 0)
{
包含满足 = true;
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/dotnetCampus.Logger.Tests/TagFilterManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ public void 单个任一和包含标签且标签顺序不影响()
Assert.IsFalse(filter.IsTagEnabled("[xxxx] Message"));
}

[TestMethod("单个任一和包含标签,只要有一个标签匹配即允许。且标签顺序不影响2。")]
public void 单个任和包含标签且标签顺序不影响2()
{
var filter = CreateFilter("+Foo,Bar");
Assert.IsFalse(filter.IsTagEnabled("[Foo] Message"));
Assert.IsFalse(filter.IsTagEnabled("[Bar] Message"));
Assert.IsTrue(filter.IsTagEnabled("[Foo][Bar] Message"));
Assert.IsFalse(filter.IsTagEnabled("[xxxx][Foo] Message"));
Assert.IsFalse(filter.IsTagEnabled("[xxxx][Bar] Message"));
Assert.IsTrue(filter.IsTagEnabled("[xxxx][Foo][Bar] Message"));
Assert.IsFalse(filter.IsTagEnabled("[xxxx] Message"));
}

[TestMethod("单个任一和排除标签,只要有一个标签匹配即不允许。")]
public void 单个任和排除标签()
{
Expand Down

0 comments on commit bceacc6

Please sign in to comment.