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

Output template support for {Properties} #825

Closed
nblumhardt opened this issue Aug 12, 2016 · 1 comment
Closed

Output template support for {Properties} #825

nblumhardt opened this issue Aug 12, 2016 · 1 comment

Comments

@nblumhardt
Copy link
Member

Via: http://stackoverflow.com/questions/38894310/serilog-saving-event-properties-added-with-forcontext-into-flat-files

When writing log files (and to the console), it's sometimes desirable to include various properties not formatted into the message, and not explicitly specified in the output template.

This might look like:

Log.Logger = new LoggerConfiguration()
    .WriteTo.Console(outputTemplate: "{Level:u2} {Message} {Properties}{NewLine}")
    .CreateLogger() ;

Log.ForContext("Foo", 42)
    .Information("Hello from {Bar}!", "bar");

// -> INF Hello from "bar"! {Foo: 42}

Note that the properties written should exclude those already formatted into the template; it's a text logging scenario, if a full property listing is desired one of the JSON formatters will cover that case.

Marked breaking because this will interfere will logs that already use a static {Properties} element in their output templates, though in practice I can't see this appearing in many places.

@nblumhardt
Copy link
Member Author

(It's possible to hack this into OutputProperties today without a huge amount of overhead, but rewriting OutputProperties to work more efficiently would be a great general improvement - there are a few unnecessary allocations we could clean up in there.)

Pliner added a commit to skbkontur/serilog that referenced this issue Mar 6, 2017
Pliner added a commit to skbkontur/serilog that referenced this issue Mar 8, 2017
Twinki14 pushed a commit to Twinki14/CitizenFX.Extensions.Client.Serilog that referenced this issue Dec 30, 2023
Fixes serilog#825 - output template support for `Properties`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant