Take the 2-minute tour ×

Does NLog have any sort of functionality to consolidate repetitive log messages when logging to a file?

Instead of:

09/08/2011 17:48:12  Your Foo hit a Bar
09/08/2011 17:48:13  Your Foo hit a Bar
09/08/2011 17:48:14  Your Foo hit a Bar
09/08/2011 17:48:15  Your Foo hit a Bar
09/08/2011 17:48:16  Your Foo hit a Bar

do this:

09/08/2011 17:48:16  [4 additional messages just like the last one]

In the grand scheme of things, this is not a big deal -- but it would help me cut down some of the 'chattiness' in our debugging logs.


share|improve this question
How would you define the rules for grouping? The same message repeated multiple times without interruption? Which timestamp would you use (first occurance)? –  ccellar Sep 13 '11 at 20:07
I was thinking if the current message was identical to the most recent 'written' message, it would be grouped. The timestamp would be the time of the last identical message. I like your buffer idea below. I might take a crack at forking the FileTarget to try it. –  David Montgomery Sep 13 '11 at 21:40
add comment

1 Answer

up vote 1 down vote accepted

There is no target in NLog which solves your issue out of the box. If you really need this, you would have to implement your own wrapper target which buffers the message for a short time (to detect the repitions) and passes it to the actual target.

If you have problems to analyze your log, you should either use a tool to filter the log or you should rethink your approach to logging. Is this information necessary? If yes, keep it as it is atm. The timestamps alone could be an useful inormation. If not, change your logging approach and log only useful information.

share|improve this answer
I agree with your assessment -- eliminate unnecessary/useless logging. However, I was really hoping to remain a lazy programmer and avoid doing any thinking and/or work! ;) –  David Montgomery Sep 13 '11 at 21:28
add comment

Your Answer


