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

Option to use synchronous logging #59

Open
JobaDiniz opened this issue Sep 25, 2022 · 3 comments
Open

Option to use synchronous logging #59

JobaDiniz opened this issue Sep 25, 2022 · 3 comments

Comments

@JobaDiniz
Copy link

On short-lived applications such as command line interfaces, using async is not optional and logs are not written.

Can we add an option to the AddFile to use synchronous log?

@nblumhardt
Copy link
Member

Hi! I think you can get the behavior you want by disposing your ServiceProvider before the application exits - does this help? Flush-per-event is generally very slow (although it's supported by the underlying Serilog file sink).

Best regards,
Nick

@JobaDiniz
Copy link
Author

JobaDiniz commented Sep 30, 2022

I'm using System.CommandLine package and their ServiceProvider is internal and does not implement IDisposable.

I think serilog-extensions-logging-file shouldn't assume we're using Microsoft.Extensions.DependencyInjection.ServiceProvider. Although such class is disposable, the IServiceProvider interface is not IDisposable.

Flush-per-event is generally very slow.

I think that's fine for short-live applications such as CLI. I believe making async is slower for CLI to be honest.

Which instance from Serilog do I need to dispose in order to flush the logs before the application exits?

@nblumhardt
Copy link
Member

Hi! This might be valuable feedback for the System.CommandLine folks; though, my guess is that they'll already have some APIs available for switching IoC containers etc. It's pretty common for services to require disposal - plugging in a regular container, or using the generic host via UseHost() should sort this out.

If you were to use Serilog directly instead, then disposing the Serilog Logger, or a SerilogLoggerProvider wrapping it, would be the way to go.

It sounds like this is a bit of a pain at present, but I don't think it's something within the scope of what this simplified package should address; disposing loggers to flush them is extremely common (as is disposal of all kinds of services).

Hope this helps,
Nick

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

2 participants