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

Is there the "force send all logs from buffer" feature? #102

Open
kanybekov opened this issue Mar 19, 2020 · 8 comments
Open

Is there the "force send all logs from buffer" feature? #102

kanybekov opened this issue Mar 19, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@kanybekov
Copy link

Hello! First of all, thank you for this library, I really like to use it.

I'm sorry if it's not the right place to ask my question.
Here is it. I have a desktop application that connected to external API and sends logs to it.
So I want to handle a situation when I need to be sure that all logs from the buffer are sent and only after I want to shut down this desktop app
I checked the repository code but didn't find anything similar. So, is there a feature like this or should I look for a workaround?

@github-actions
Copy link
Contributor

Hi there and welcome to this repository!

A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it.

@FantasticFiasco
Copy link
Owner

Hi!

I don't think individual sinks have the option to flush, but Serilog itself does. Look for CloseAndFlush in this article. Try it out and see if it's what you are looking for.

@FantasticFiasco
Copy link
Owner

FantasticFiasco commented Mar 19, 2020

The more I think about it, the trickier it gets.

It hasn't to do with whether the log events are saved on disk or only held in memory. It has to do with the fact that there are external dependencies that might not accept the log events, and what should then happen? We cannot prevent the process from terminating indefinitely.

One of the better solutions would be to provide a timeout to the flush operation, aborting if flushing isn't complete before the timeout hits. But this isn't something I've planner for, nor is it something that has been requested by any other than yourself.

@FantasticFiasco FantasticFiasco added the enhancement New feature or request label Mar 19, 2020
@sunib
Copy link

sunib commented Sep 21, 2020

I'm running into this right now. I've got a small console program that is logging some stuff and then terminates. I do call Log.CloseAndFlush(); at the and and kind of expected this to wait until all logs where send through HTTP. I've opened fiddler and noticed that it's not even starting a connection to my destination endpoint. The application is very short lived. Putting in a await Task.Delay(5000); at the end is making it working like expected. But that feels a bit awkward.

Any thoughts on this one? I might be able to help with a PR if this is appreciated, but I'm not sure if the internals of serilog even allow us to hook into the CloseAndFlush as a sink (have not looked into this).

@FantasticFiasco
Copy link
Owner

I think we ought to start with defining the requirements. I don't think we can reason on implementation details until we know what to expect from the functionality. Some of the requirements will be pretty straight forward, but there will be some edge cases that will require some discussions.

I will continually update this post with new requirements as they appear in this issue. Please help me with the requirements as you see them.

Requirements

  • Make sure that log events written to Serilog successfully gets sent to the log server, indifferent on whether the sink is durable or non-durable
  • Since we cannot guarantee that the log server accepts log events, we should be able to provide a timeout
    • Question: Should we throw an exception if the timeout occurs?
  • The API Log.CloseAndFlush() should be investigated, because an existing API is far better than defining a new

@hischampion
Copy link

I'm also running into this issue, but not because the application is shortlived. It's because I'm testing the logging and mocking out the IHttpClient (used by Http sink) to verify the formatting of the log output for NewRelic. The NewRelic sink currently does not support logging (ironically), just other NewRelic features. Anyway so I want to verify the logging JSON format etc. and I can wait 5000 in the test, but it would be nicer to just force the logs to flush on command for testing.

Is something like this possible? It doesn't have to be as "pretty" as normal code, in my opinion.

@AF250329
Copy link

AF250329 commented Aug 18, 2023

Do we have any update on this ? I am running into exactly the same problem. Short lived application does not send any logs :( even when added Log.CloseAndFlush(); at the end

@FantasticFiasco
Copy link
Owner

No progress has been made with this issue.

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

No branches or pull requests

5 participants