I am using log4net in c# console app, and I was wondering if it was possible to have each log entry include the elapsed time since the last log entry?
Right now, I am using %-4timestamp (which I believe is the milliseconds since the start of the log) so I can spin through the log later and calculate the difference between an entry and the previous entry. I was hoping there was something I could use to get the elapsed time to appear in each log message though.
Is this possible?
Thanks in advance!
EDIT
To clarify the elapsed time, I mean the amount of time that has elapsed since the last time log4net has logged a message.
For example, if I have this log:
0 [main] INFO MyApp - Entering application.
36 [main] DEBUG Com.Foo.Bar - Did it again!
51 [main] INFO MyApp - Exiting application.
Then the additional information I would like would be something like this:
0 (0) [main] INFO MyApp - Entering application.
36 (36) [main] DEBUG Com.Foo.Bar - Did it again!
51 (15) [main] INFO MyApp - Exiting application.
Where the extra value I added in between parenthesis is the elapsed time since the last log.
Why not just keep track of it and add it yourself?
Something like:
Obviously youd want to customize a bit, but this is the basic idea. I always use a wrapper class to do logging, just because it adds customization capabilities. For example, I use it to do custom exception logging like this:
That way, when I want to log exception details, I can do something like:
instead of:
And that’s just one example. There are quite a few other things that make this useful.