Issue Details (XML | Word | Printable)

Key: LOG4NET-84
Type: Improvement Improvement
Status: Closed Closed
Resolution: Invalid
Priority: Minor Minor
Assignee: Nicko Cadell
Reporter: Tal G
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Log4net

Allow messages to be printed in ascendant order according to date time.

Created: 25/Jul/06 07:42 AM   Updated: 28/Jul/06 10:36 PM
Return to search
Component/s: Appenders
Affects Version/s: 1.2.10
Fix Version/s: None

Time Tracking:
Not Specified

Environment: All

Resolution Date: 28/Jul/06 10:36 PM


 Description  « Hide
In multi threading application, when letting log4net to print time information before every message (for example with %d{HH:mm:ss.fff} layout), it might print the messages not according to ascendant order.
The reason is that the date time information is taken from LoggingEventData.TimeStamp field that is update to Now before the synchronization phase.

That is only semantic issue, but it cause inconveniency to many.


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Ron Grabowski added a comment - 25/Jul/06 11:05 PM
I don't understand what the problem is or your solution to it. Multi-threaded applications usually don't make guarantee as to the order that worker threads are processed.

Tal G added a comment - 26/Jul/06 06:15 AM
I find myself again and again need to explain to others why a message with later time is located in the log file before a message with earlier time.
So I solved the problem by taking the Now instead of loggingEvent.TimeStamp after the synchronization phase on DatePatternConverter

Ron Grabowski added a comment - 28/Jul/06 03:53 AM
You solved your problem...do you still think this is an issue for log4net in general? I don't understand how log4net is suppose to synchronize messages so they get written in the correct time order. What if I'm trying to test out a new threading algorithm and I want messages to be written in the order in which they were processed by the application or something I don't have control over (i.e. the operating system)?

Nicko Cadell added a comment - 28/Jul/06 10:33 PM
The LoggingEvent captures the event TimeStamp as close as possible to when the event occurred, not when it is written to a log file (which is the job of an appender).

If you want your log file to contain the time the log event is written to the file, rather than the time the event occurs, then you can use the following layout in your appender configuration:


<layout type="log4net.Layout.PatternLayout">
  <converter>
    <name value="datenow" />
    <type value="log4net.Util.PatternStringConverters.DatePatternConverter,log4net" />
  </converter>

  <conversionPattern value="%datenow [%thread] %-5level %logger - %message%newline" />
</layout>

Nicko Cadell added a comment - 28/Jul/06 10:36 PM
Closing this issue as invalid because it is a usage requirement that can be resolved by correct configuration of log4net. No further action required.