Last active
November 3, 2015 22:31
-
-
Save dimitrispaxinos/83c6b01ef3122db63f6d to your computer and use it in GitHub Desktop.
Serilog: Log using a structured Object in the context
This file contains hidden or 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" | |
| }; | |
| // 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