Nlog: Flush on Fatal

Created on 26 Feb 2019  路  3Comments  路  Source: NLog/NLog

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:

  • Target receives event
  • If event has level L or higher (for example: L == Error) - target should be flushed immediately after adding event
  • Otherwise: event should be flushed only if buffer overflow action Flush is selected.

Why do we need this:

  • Sometimes the last application event is 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.
  • Some applications can be configured with huge buffer timeout (~1 minute) just to decrease IO operations (because operating logging can be not important). However 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.
  • The most of application does not have 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):

  • If this feature is missing - I suggest to add this by:

    • Creating new property for configuration

    • Implementing new behavior inside the target (the same with #2276)

    • Adding tests

  • In both cases (if it is already supported or not): I suggest update documentation by publishing this behavior
question

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.

All 3 comments

@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()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ranjan-2209 picture ranjan-2209  路  3Comments

vasumsit picture vasumsit  路  3Comments

Rapiiidooo picture Rapiiidooo  路  3Comments

ErcinDedeoglu picture ErcinDedeoglu  路  3Comments

vdasus picture vdasus  路  3Comments