Last active
October 31, 2015 13:22
-
-
Save dimitrispaxinos/7e0c9389e98a845b9938 to your computer and use it in GitHub Desktop.
Serilog: Add Structured Objects to your Log Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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