Closed paulbarron85 closed 10 months ago
The best way would be if the logger buffered these messages until the time is valid and then write them to the file. Since it already has a buffer built-in, this should be easy to implement. It always takes a few cycles until the time information is available.
Meanwhile, as a workaround, you can just use the DateTime
function block as dummy because it exposes a Done
property and trigger your logging once it becomes true
. The same function block is used internally, so I'd expect the done
bits to be in sync. See here.
I'll look into the buffering as well this weekend.
As a side note, you could simplify the logic of your first logging by leveraging the built-in string builder and any-to-string
casts:
_logger
.OnCondition(bFirstScan)
.AppendString('Initial value is ')
.AppendAny(bInput)
.Warning();
This issue has been fixed with the latest release.
It buffers messages so that the timestamp in the filename is always valid. Additionally, it exposes the TimeInfoReady
property that can be used to trigger messages only once a valid timestamp is available. See here.
As a side note, you could simplify the logic of your first logging by leveraging the built-in string builder and any-to-
string
casts:_logger .OnCondition(bFirstScan) .AppendString('Initial value is ') .AppendAny(bInput) .Warning();
Only problem here is that it prints bool True as 1 and False as 0. I prefer it to print True/False.
What is the best way to write log messages on the first couple of PLC scans after restarting. I would like to implement something like the following in a POU:
With the POU being calling like so from MAIN:
However I end up getting two files written as below: With the contents of the first file being:
It looks like the time hasn't been updated yet to the local time. Is it possible to expose DateTime._localSystemTime.bValid? Or is there a better way of doing this?