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

Prevent empty log file at startup #18

Open
TIPConsulting opened this issue Dec 19, 2020 · 4 comments
Open

Prevent empty log file at startup #18

TIPConsulting opened this issue Dec 19, 2020 · 4 comments

Comments

@TIPConsulting
Copy link

The core tool creates a new empty file as soon as the logger is initialized. This works fine if you use a non-granular naming scheme, like "LogFile.log" because all of your logs will then be appended to the same file. However, when using granular file names - like adding a timestamp to the file name - the initial log file remains empty. This adds noise to the log output folder.

It would be very helpful if files were only created when a message is being written

@VitaliyMF
Copy link
Contributor

This sounds reasonable; I need to check if it is possible to create a file in a 'lazy' manner when 'FormatLogFileName' delegate is provided.

@VitaliyMF
Copy link
Contributor

I've just checked the code and it seems when logger is initialized it creates an empty file but it is resolved with 'FormatLogFileName' delegate - so it is a bit unclear how log file may remain empty (only when app doesn't write anything to a log for a long time?..).

I may explain why a log file is opened/created on the initialization stage: this is performed from the app main thread, and if target folder is not writable exception will block app start. I think current behavior should be preserved, and lazy log file creation may be forced with a special option only when needed.

@TIPConsulting
Copy link
Author

so it is a bit unclear how log file may remain empty (only when app doesn't write anything to a log for a long time?..).

That is essentially the problem, yes. I like to have granular log file names that includes a timestamp with seconds. So the calculated file name changes by the time that a log is written.

@VitaliyMF
Copy link
Contributor

I like to have granular log file names that includes a timestamp with seconds.

wow, that's pretty unusual usage of the file logger (a new file for each second!).
I think a new option smth like 'LazyFileOpen' may be introduced to control a log file opening (init time vs first log message).

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

No branches or pull requests

2 participants