I'm trying to provide a Logger using a queue system and Timer to to reduce logging time on my main thread. However I would like to capture the time in which a log message was created instead of when the log message was written. While I could add the timestamp to the message, I would like the option to provide the timestamp to log4net so that I can use the pattern provider to format the written log message.

If providing the timestamp value is not possible. A way to easily format the message pattern before logging would be great.

2 Answers
2

When you take a look at the log4net implementation internals you will see that the timestamp is not created when writing logs by the appender but when constructing instances of LoggingEvent. In the abstract Logger class of log4net a new LoggingEvent instance is created that contains a timestamp set to DateTime.Now. You can use this timestamp in your appenders.

The reason for assigning the timestamp manually is that I've implemented a queuing system. In the queuing system, the logging event is done using a timer, currently 100ms. After doing some tests using the queuing system, I see that timestamps i provide vs the timestamps from log4net can be 200ms+. This can be seen by the example I gave in my post which shows 100ms difference.
–
galford13xDec 17 '11 at 17:38

That means you're first queuing the log message and at certain times logging in a batch to log4net? You did not implement an appender? The appender approach would be the "right way" for such a queuing implementation...
–
saintedlamaDec 19 '11 at 19:05

You're right, I implemented a batch logger that appends to log4net at certain intervals if log messages are in the queue. I'll look into creating my own appender as that does sound like a better approach. Thanks for the tip, for some reason it didn't occur to me to take that route.
–
galford13xDec 27 '11 at 23:37