NLog avoid repeated lines and set delta time

Viewed 161

I am using Nlog and couldn't find the features here below. Of course I could make them by myself but since NLog usually takes care of all needs perhaps might have all this built-in.


Delta seconds between each entry

I have the layout as "[${date:format=dd.MM.yyyy HH\:mm\:ss.fff}] (${level:uppercase=true}): ${message}" So that I get something like:

[20.05.2021 11:53:33.667] (INFO): --- 20210520_1153 Starting ---
[20.05.2021 11:53:33.784] (INFO): *.cfg not found going for TRIAL LICENCE
[20.05.2021 11:53:33.784] (INFO): Reg Hive found. Verifying
[20.05.2021 11:53:33.784] (INFO): Key length = 3

Is it possible to automaticalla add delta time? so like here below

[20.05.2021 11:53:33.667 - 0.000] (INFO): --- 20210520_1153 Starting ---
[20.05.2021 11:53:33.784 - 0.117] (INFO): *.cfg not found going for TRIAL LICENCE
[20.05.2021 11:53:33.784 - 0.000] (INFO): Reg Hive found. Verifying
[20.05.2021 11:53:33.784 - 0.000] (INFO): Key length = 3

Avoid repeated lines (at will)

[20.05.2021 11:53:33.667] (INFO): AAA
[20.05.2021 11:53:33.784] (INFO): AAA
[20.05.2021 11:53:33.784] (INFO): AAA
[20.05.2021 11:53:33.784] (INFO): AAA

to become something like

[20.05.2021 11:53:33.667] (INFO): AAA
...

And to be able to extend that also to more than one level

[20.05.2021 11:53:33.667] (INFO): AAA
[20.05.2021 11:53:33.784] (INFO): BBB
[20.05.2021 11:53:33.784] (INFO): AAA
[20.05.2021 11:53:33.784] (INFO): BBB

to become

[20.05.2021 11:53:33.667] (INFO): AAA
[20.05.2021 11:53:33.784] (INFO): BBB
...

That would save a lot of chars

Thanks in advance

Patrick

2 Answers

These features (especially the second) would require a continuous parsing of the content of the existing log file, which is going to significantly impact performance.
I doubt NLog will contain a re-parsing feature, and even if it did, I doubt it'd be a good idea to use it.

In both cases, it is significantly easier to preprocess the writing of the log message than it is to retroactively have to re-parse the log and figure out of the current log message should be written or not.

Related