Skip to content

How to write JSON to file? #4

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
txchen opened this issue Jul 1, 2016 · 3 comments
Closed

How to write JSON to file? #4

txchen opened this issue Jul 1, 2016 · 3 comments

Comments

@txchen
Copy link

txchen commented Jul 1, 2016

Is there a way to write the structured log to file (in json)?

@txchen
Copy link
Author

txchen commented Jul 1, 2016

I found https://github.com/nblumhardt/serilog-sinks-json and it is working.

However I still think serilog should support this officially.
Write json to log file can be useful when using some log shipper to read file and then write to log store (like elasticsearch). Although we already have the ES sink, I think writing json to file has the following advantages:

  • more reliable to write to local file than remote service
  • during development, we can easily see the structured data, without having to run a Seq instance or ElasticSearch.

@nblumhardt
Copy link
Member

Hi! Yes, we've been working through a few changes to support this here. The API will look like:

.WriteTo.File(new JsonFormatter(), "C:\\myapp.json")

The overload accepting an ITextFormatter is not present today, but will be added soon.

Regards,
Nick

@migellars
Copy link

Hi! Yes, we've been working through a few changes to support this here. The API will look like:

.WriteTo.File(new JsonFormatter(), "C:\\myapp.json")

The overload accepting an ITextFormatter is not present today, but will be added soon.

Regards, Nick

Hello, how about you are fetching the with ReadFrom.Appsettings. how do I use new JsonFormatter

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

3 participants