<layout type="log4net.Layout.PatternLayout">
 <converter>
  <name value="e" />
  <type value="MillisecondsSinceLastLoggingEvent" />
 </converter>
 <conversionPattern value="%5level %e %message%newline" />
</layout>

 public class MillisecondsSinceLastLoggingEvent : 
  PatternLayoutConverter
 {
  private DateTime lastTimeStamp;
  private bool firstTimeStamp = true;

  protected override void Convert(
   TextWriter writer, LoggingEvent loggingEvent)
  {
   if (firstTimeStamp)
   {
    writer.Write(0);
    firstTimeStamp = false;
   }
   else
   {
   writer.Write(
   (loggingEvent.TimeStamp - lastTimeStamp).TotalMilliseconds);
   }
   lastTimeStamp = loggingEvent.TimeStamp;
  }
 }

--- "Urban Jaroslav, Ing." <[EMAIL PROTECTED]> wrote:

> 2 Göran Roseen
> ------------------------------------
> Thanx for tip, but it is not exactly what I am looking for. This
> timestamp just shows the time increment since logging is started. I
> am looking rather for time difference between logged events.
> 
> 
> I found that for timestamp can be used char r, which is inserted in
> PatternLayout. Did you mean this?
> 
> r - Used to output the number of milliseconds elapsed since the start
> of the application until the creation of the logging event. 
> 
> 
> 2 Nicko Cadell
> -----------------------------------
> Just difference between actual event and event called before. See
> better example (see values in first bracket column):
> 
> 2005-11-08 11:15:42,106 [0,012] [3444] INFO  XmlService
> --->GetSoapBody
> 2005-11-08 11:15:42,341 [0,235] [3444] INFO  XmlService
> --->XSDValidation
> 2005-11-08 11:15:45,652 [3,311] [3444] INFO  XmlService
> --->XSLTValidation
> 
> Then I can see the highest values of time increment, which I am
> interested in.
> JU
> 
> 
> 
> -----Original Message-----
> From: Urban Jaroslav, Ing. 
> Sent: Tuesday, November 08, 2005 12:24 PM
> To: [email protected]
> Subject: PatternLayout - add time increment
> 
> Hi all,
>       I looked for solution how I could insert to log file an time
> increment consecutive records. As I studied the PatternLayout for
> log4net, found no possibility to achieve it.
>       Is there anyone who solved it or it is not possible?
> 
>       Thanks for any response, bye Jaroslav Urban
> 
> An example:
> 2005-11-08 11:15:42,106 [0,000] [3444] INFO  XmlService [] -
> -->GetSoapBody
> 2005-11-08 11:15:42,106 [0,000] [3444] INFO  XmlService [] -
> -->Validation
> 2005-11-08 11:15:43,106 [1,000] [3444] INFO  XmlService [] -
> -->XSLTValidation
> 
> 
> Specification:
> - log4net v1.1.1.33753
> - IIS project
> - using Dot.Net Fr1.1
> 
> 

Reply via email to