Skip to content

Instantly share code, notes, and snippets.

@dimitrispaxinos
Last active November 3, 2015 22:31
Show Gist options
  • Save dimitrispaxinos/83c6b01ef3122db63f6d to your computer and use it in GitHub Desktop.
Save dimitrispaxinos/83c6b01ef3122db63f6d to your computer and use it in GitHub Desktop.
Serilog: Log using a structured Object in the context
// Declare Person class
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
// Instantiate a Person
var person = new Person()
{
FirstName = "Dimitris",
LastName = "Paxinos"
};
// Provide the object and set the desctructureObjects parameter to true
// in order to get the full object in your log event
using (LogContext.PushProperty("PersonDetails", person, destructureObjects: true))
{
Log.Logger.Information("This log entry includes a structured object");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment