Skip to content

[Feature] File header #42

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

Closed
strohhut opened this issue Dec 3, 2016 · 14 comments
Closed

[Feature] File header #42

strohhut opened this issue Dec 3, 2016 · 14 comments

Comments

@strohhut
Copy link

strohhut commented Dec 3, 2016

I want to use CSV format when logging so every generated file should have the fields as first line.

I think it would be nice if there was a file created event that allows to insert text.

@nblumhardt
Copy link
Member

Interesting scenario - thanks for the note. Will need to have a think about how this would fit in.

@strohhut
Copy link
Author

strohhut commented Dec 5, 2016

Thanks for considering it. A file created event might also be nice for some other use cases e.g. to run some code that archives the previous log file. It would be nice if the event contained some info like the name of the new file the reason why there's a new file (e.g. old file got too big or because a time limit was reached).

@PaulDotNet
Copy link

File headers are very useful sometimes for long running services when the first log could be already deleted or if service was restarted multiple times.

@bikash7411
Copy link

Is there any way to add headers in txt file generated by serilog ?

@jeremyellul
Copy link

jeremyellul commented Jun 12, 2018

In our latest projects we required to mimic IIS logs, to achieve this we needed to create a header in every rolling file. We've forked from "serilog-sinks-rollingfile" and added this functionality, would you be interested in considering this changeset?

@bikash7411
Copy link

bikash7411 commented Jun 12, 2018 via email

@jeremyellul
Copy link

I cannot push the branch, it seems that I don't have access rights.

image

@bikash7411
Copy link

Can you give some details .
How you implemented or if you can send me sample code to my email id ([email protected])

@nblumhardt
Copy link
Member

This is now available via serilog/serilog-sinks-file#80 - let me know if you need any help/pointers wiring it up (no docs just yet :-))

@cocowalla
Copy link

@strohhut @bikash7411 @jeremyellul I've just published a NuGet package, Serilog.Sinks.File.Header, which contains a header-writing implementation based on the supporting work merged into dev from #80 - just let me know if you encounter any issues

@emiliovmq
Copy link

This is really great and it has my 10 thumbs up. I'm really interested in using it. However, I have a different scenario where all my Serilog's sinks are configured through a json file. It is possible to use the new package while reading the settings from a json file? I know this scenario is very complicated but just want to hear your thoughts about that.

@cocowalla
Copy link

@emiliovmq Yes, I usually use JSON configuration too - it's not totally obvious how to configure hooks though, so I have a section in the readme in the GitHub repo 😄

@emiliovmq
Copy link

emiliovmq commented May 6, 2019 via email

@cocowalla
Copy link

cocowalla commented May 6, 2019

@emiliovmq no exactly support for DI, but yes, you can supply a factory method (Func<string>) instead of a static string, resolving the header at runtime using your cached values.

You would typically configure this static factory method once, during startup, when you're configuring logging and other infrastructure concerns.

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

No branches or pull requests

7 participants