DocumentationDiscussions
DocumentationDiscussions

Discussions

Ask a Question
Back to All

Logging object properties with nlog

Hi

Trying to log properties so they are searchable using NLog.
I know I can use @ to serialize objects in messages - but how to do the same for properties?

Pseudo c# code that works (I can e.g. search for x.status=0 ):
class MyClass { public int status { get; set; } };
var x = new MyClass();
log.Debug().Message("Write {@x}", x).Write();

Pseudo c# code no working (only x class name is serialized):
class MyClass { public int status { get; set; }
var x= new MyClass();
log.Debug().Message("Write Hi").Property("x", x).Write();

How do I make MyClass serailized so I can search i when logging it as a user Property

Regards