-
-
Notifications
You must be signed in to change notification settings - Fork 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
Prevent creating empty log files #636
Comments
Heya @Zerowalker , Would be something like this: $paramSetPSFLoggingProvider = @{
Name = "logfile"
FilePath = "$PSScriptRoot\logs\%Date%.csv"
LogRotatePath = "$PSScriptRoot\logs\*.csv"
Enabled = $true
NoEmptyLog = $true
}
Set-PSFLoggingProvider @paramSetPSFLoggingProvider And at the end of your script: Disable-PSFLoggingProvider -Name logfile Can't make it automatic, as people might have switched to considering the empty files as proof of execution (just nothing going wrong) and alert on them missing, so I can't just drop that. But with the parameter as described, that I can do. I'll keep this issue open as a marker to make it happen in the next release (no solid ETA, sorry), but I'll update here once it's shipped, so you'll get notified :) |
Hey @FriedrichWeinmann, Hmm, what is this change that requires the file to be created before hand? As you say the empty file can be used as proof of execution, didn't think of that, a good reason to have it really. Why would you need Having an option Nevertheless I do appreciate the suggestion, many thanks! |
Originally, each message would get written using a new
This meant I needed to switch the way I write the file, keep it in access. So I shifted over to a [System.IO.StreamWriter], allowing me direct control over everything I needed, at the cost of creating the file always.
The background logging happens in 5 stages: Initialize, Begin, Process, End, Finalize. Initialize happens once only at the beginning. Then it will keep looping Begin/Process/End until either a) PowerShell closes, b) The logging Provider has been disabled or C) The End Of Time. Finally it will once only run Finalize.
In my experience, most of the times we have some more messages in a script than just when things fail, meaning the empty-logfile-syndrome should be quite rare. |
Ah that make sense. I unserstand and agree about your approach on this, lack of control and potential issues are quite a big bottleneck compared to the "empty file issue":)
Doesn't
My case is probably rare than, I did log more things before, but as the log files are really only used about errors for me, But in that case please do with my request as you will, you taking your time to consider it is appreciated just in itself! |
No. By the time we reach PSFramework registers an event when it is first imported that triggers when PowerShell shuts down, in order to flush the messages in the queue (but it does not disable the logging providers or wait for them to be Finalized). Btw., there's some rare edge-cases where we lose a last message anyway and I'd also always recommend setting an |
Ah okay that's great. As for the EDIT: Oh wait, that's |
You can have multiple parallel enabled logging providers by giving each instance its own name.
It has one more edge-case issue (your scenario probably doesn't suffer from): |
Got it, so in that case having a script with a log file setup calling another script that also does this can mess things up if they don't specify an I just tried using |
Got it thanks!
|
Not sure which version this started happening, but if you do something like
This will end up creating a log file even if nothing is ever written.
For cases where it's common that nothing happens for most days, it's a bit annoying to have a ton of log files even though just some actually may contains something.
So if possible it would be nice if the files are only created when something is actually written to it.
The text was updated successfully, but these errors were encountered: