Skip to content

Commit

Permalink
Allow child message lookup by text instead of name (which is null for…
Browse files Browse the repository at this point in the history
… messages)
  • Loading branch information
KirillOsenkov committed Jun 16, 2017
1 parent d97255a commit 63dedaa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/StructuredLogger/ObjectModel/ChildrenList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public T FindNode<T>(string name) where T : NamedNode
{
for (int i = 0; i < Count; i++)
{
if (this[i] is T t && t.Name == name)
if (this[i] is T t && t.LookupKey == name)
{
childrenCache[key] = t;
return t;
Expand All @@ -41,14 +41,14 @@ private void EnsureCacheCreated()

public void OnAdded(NamedNode child)
{
if (child?.Name == null)
if (child?.LookupKey == null)
{
return;
}

EnsureCacheCreated();

var key = new ChildrenCacheKey(child.GetType(), child.Name);
var key = new ChildrenCacheKey(child.GetType(), child.LookupKey);
childrenCache[key] = child;
}

Expand Down
2 changes: 2 additions & 0 deletions src/StructuredLogger/ObjectModel/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Message : TextNode, IHasRelevance
/// </summary>
public DateTime Timestamp { get { return DateTime.MinValue; } set { } }

public override string LookupKey => Text;

private bool isLowRelevance = false;
public bool IsLowRelevance
{
Expand Down
1 change: 1 addition & 0 deletions src/StructuredLogger/ObjectModel/NamedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class NamedNode : TreeNode
{
public string Name { get; set; }

public virtual string LookupKey => Name;
public override string ToString() => Name;
}
}
2 changes: 1 addition & 1 deletion src/StructuredLogger/ObjectModel/TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public virtual T FindChild<T>(string name) where T : NamedNode
return list.FindNode<T>(name);
}

return FindChild<T>(c => c.Name == name);
return FindChild<T>(c => c.LookupKey == name);
}

public virtual T FindChild<T>(Predicate<T> predicate)
Expand Down

0 comments on commit 63dedaa

Please sign in to comment.