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

Suggestion: Make default template public #335

Open
SeanKilleen opened this issue Feb 1, 2025 · 3 comments · May be fixed by #336
Open

Suggestion: Make default template public #335

SeanKilleen opened this issue Feb 1, 2025 · 3 comments · May be fixed by #336

Comments

@SeanKilleen
Copy link

SeanKilleen commented Feb 1, 2025

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. For example, "I'd like to do x but currently I can't because y [...]".

I'd like to keep the existing template almost entirely as-is, including across future Serilog updates. But, I'd like to modify one aspect of it, which I'm willing to take on myself.

However, in FileConfigurationExtensions.cs, DefaultOutputTemplate is a private constant rather than a public one, so I'm unable to programmatically modify it to suit my needs. I must instead copy/paste it.

https://github.com/serilog/serilog-sinks-file/blob/dev/src/Serilog.Sinks.File/FileLoggerConfigurationExtensions.cs#L35

Describe the solution you'd like

I'd like DefaultOutputTemplate to be a public constant. This way I can reference it in constructing my own template.

Describe alternatives you've considered

Copying/pasting DefaultOutputTemplate into my code and adding a comment indicating where I got it from.

Additional context

I want to output the HttpRequestId that comes from .Enrich.WithHttpRequestId() as part of this particular log file, to make tracing through files easier. So I'm looking to do something along the lines of:

var template = FileLoggerConfigurationExtensions.DefaultOutputTemplate
        .Replace("[{Level:u3}] ", "[{Level:u3}] [Request {HttpRequestId}] ");

// Use template in Serilog

I'll submit a PR on this just in case you're interested, as the work itself is small. I couldn't find any historical precedent on whether it is considered acceptable to make the template public.

@SeanKilleen SeanKilleen linked a pull request Feb 1, 2025 that will close this issue
@SeanKilleen
Copy link
Author

SeanKilleen commented Feb 1, 2025

To be clear, I'm not sure this is something that a lot of folks want to do in a typical situation vs having their own const and not taking the performance hit. So it's totally acceptable for me if the aim is to hide this so that people reach that conclusion by default. If that's the case, feel free to disregard and close. 👍

@nblumhardt
Copy link
Member

Thanks for the suggestion and PR, @SeanKilleen 👍

I've wondered about this too, in the past - definitely times when it would be handy. Discoverability is not ideal, and there are some questions around evolution and breaking changes that I think leave this on just short of enough benefit to get across the line.

I'll leave this open for the time being so that anyone interested can chime in. Cheers!

@SeanKilleen
Copy link
Author

@nblumhardt yeah, I hear you for sure. Discoverability is not ideal, and yet I discovered it quickly enough. Turned it into my own const with a link to where I found it. Seems like the way to go, honestly. I'm leaning toward closing this one myself; no worries if someone else does.

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

Successfully merging a pull request may close this issue.

2 participants