Skip to content

Commit 63dedaa

Browse files
committed
Allow child message lookup by text instead of name (which is null for messages)
1 parent d97255a commit 63dedaa

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

src/StructuredLogger/ObjectModel/ChildrenList.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public T FindNode<T>(string name) where T : NamedNode
2020
{
2121
for (int i = 0; i < Count; i++)
2222
{
23-
if (this[i] is T t && t.Name == name)
23+
if (this[i] is T t && t.LookupKey == name)
2424
{
2525
childrenCache[key] = t;
2626
return t;
@@ -41,14 +41,14 @@ private void EnsureCacheCreated()
4141

4242
public void OnAdded(NamedNode child)
4343
{
44-
if (child?.Name == null)
44+
if (child?.LookupKey == null)
4545
{
4646
return;
4747
}
4848

4949
EnsureCacheCreated();
5050

51-
var key = new ChildrenCacheKey(child.GetType(), child.Name);
51+
var key = new ChildrenCacheKey(child.GetType(), child.LookupKey);
5252
childrenCache[key] = child;
5353
}
5454

src/StructuredLogger/ObjectModel/Message.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Message : TextNode, IHasRelevance
99
/// </summary>
1010
public DateTime Timestamp { get { return DateTime.MinValue; } set { } }
1111

12+
public override string LookupKey => Text;
13+
1214
private bool isLowRelevance = false;
1315
public bool IsLowRelevance
1416
{

src/StructuredLogger/ObjectModel/NamedNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class NamedNode : TreeNode
44
{
55
public string Name { get; set; }
66

7+
public virtual string LookupKey => Name;
78
public override string ToString() => Name;
89
}
910
}

src/StructuredLogger/ObjectModel/TreeNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public virtual T FindChild<T>(string name) where T : NamedNode
140140
return list.FindNode<T>(name);
141141
}
142142

143-
return FindChild<T>(c => c.Name == name);
143+
return FindChild<T>(c => c.LookupKey == name);
144144
}
145145

146146
public virtual T FindChild<T>(Predicate<T> predicate)

0 commit comments

Comments
 (0)