Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogViewer: Adding support for viewing destructed properties #13357

Conversation

enkelmedia
Copy link
Contributor

Description

This simple PR addes support for "destructed properties" for the log viewer in the back office.

What is a destructed property?
Serilog stores properties associated with a log entry in different ways. Stringification is when Serilog will basically just call .ToString() on a parameter passed into the log method-call. Serilog also supports storing the property as a object, by Destructuring the object. This can be done in different ways but one simple way is to add a @ sign before the the name of the parameter inside the placeholder in the message template, like this:

_logger.LogWarning("Not good {@Data1} and {@Data2}", data1, data2);

In this scenario, Serilog stores the variables as objects which makes them easier to look at in the logs. Some more info can be found here: https://github.com/serilog/serilog/wiki/Structured-Data. Using Enrichers we can also add more properties to the log entry that is not a part of the message template - hence before this PR it's impossible to see that data in the UI.

Umbraco supports this all the way until the data is displayed in the backoffice log viewer UI, the line above will look like this

umb-logviewer-now

The data is passed from the backend controller to the view but before this PR the view did not know how to display it. With the fix in this PR the log entry details now looks like this.

umb-logviewer-destructed

Testing this PR

  • Spin up Umbraco and create some C# that writes to the log.
  • Make sure to pass a "complex object" as one of the parameters.
  • Look at the log entry details and see the JSON-formatted representation of the destructed property.

@nul800sebastiaan
Copy link
Member

This is really lovely, very useful, thanks very much @enkelmedia! 💪

@nul800sebastiaan
Copy link
Member

Cherry picked for 10.4.0 3bd9da0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants