NLog version: 4.5.0
Platform: ..Net 4.5
Could you please help, can NLog flush events immediately (in blocking manner) in case of receiving event with target level? Possible this ticket is related to #2276.
Expected behavior:
Error) - target should be flushed immediately after adding eventFlush is selected.Why do we need this:
Error/Fatal. It means that application will be exited/self-killed immediately after logging action. And in this case the last event is very important.Error event is frequent during the Staging/Testing, so ideally critical log event should we written immediately, however all other events can be written with delay.Error/Fatal events frequent. Moreover: often Error event is not normal behavior, e.g. slow down in this case is correct.Different ways of implementation (I can do this by myself):
@imanushin NLog only has the AutoFlushWrapper that can trigger on LogEvent-LogLevel:
https://github.com/NLog/NLog/wiki/AutoFlushWrapper-target
This can then be combined with BufferingWrapper that can be configured with overflowaction=discard (only write on flush):
https://github.com/nlog/NLog/wiki/BufferingWrapper-target
If you have more advanced logic, then you are very welcome to create a PullRequest and show your ideas.
I assume your question has been answered, if not, please let us know!
@imanushin New property FlushOnConditionOnly has been added to AutoFlushWrapper in NLog 4.6.6 . See also #3513
It ensures that messages are NOT flushed when calling NLog.LogManager.Flush() or NLog.LogManager.Shutdown()
Most helpful comment
@imanushin NLog only has the AutoFlushWrapper that can trigger on LogEvent-LogLevel:
https://github.com/NLog/NLog/wiki/AutoFlushWrapper-target
This can then be combined with BufferingWrapper that can be configured with overflowaction=discard (only write on flush):
https://github.com/nlog/NLog/wiki/BufferingWrapper-target
If you have more advanced logic, then you are very welcome to create a PullRequest and show your ideas.