Skip to content

Instantly share code, notes, and snippets.

@dimitrispaxinos
Last active October 31, 2015 13:22
Show Gist options
  • Save dimitrispaxinos/7e0c9389e98a845b9938 to your computer and use it in GitHub Desktop.
Save dimitrispaxinos/7e0c9389e98a845b9938 to your computer and use it in GitHub Desktop.
Serilog: Add Structured Objects to your Log Event
// 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"
};
// Passing a structured object the way we did previously with the strings
Log.Logger.Information("I am now logging a structured object without @: {PersonDetails}", person);
// Prefixing the property name with @ will pass the complete object
Log.Logger.Information("I am now logging a structured object with @: {@PersonDetails}", person);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment