Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TimestampLocalLogger.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 namespace SiliconStudio.Core.Diagnostics
7 {
8  /// <summary>
9  /// A logger that stores messages locally with their timestamp, useful for internal log scenarios.
10  /// </summary>
12  {
13  private readonly DateTime startTime;
14 
15  /// <summary>
16  /// Initializes a new instance of the <see cref="LoggerResult" /> class.
17  /// </summary>
18  public TimestampLocalLogger(DateTime startTime, string moduleName = null)
19  {
20  this.startTime = startTime;
21 
22  Module = moduleName;
23  Messages = new List<Message>();
24 
25  // By default, all logs are enabled for a local logger.
26  ActivateLog(LogMessageType.Verbose);
27  }
28 
29  /// <summary>
30  /// Gets the messages logged to this instance.
31  /// </summary>
32  /// <value>The messages.</value>
33  public List<Message> Messages { get; private set; }
34 
35  protected override void LogRaw(ILogMessage logMessage)
36  {
37  TimeSpan timestamp = DateTime.Now - startTime;
38  Messages.Add(new Message(timestamp.Ticks, logMessage));
39  }
40 
41  /// <summary>
42  /// A structure describing a log message associated with a timestamp.
43  /// </summary>
44  public struct Message
45  {
46  /// <summary>
47  /// The timestamp associated to the log message.
48  /// </summary>
49  public long Timestamp;
50 
51  /// <summary>
52  /// The log message.
53  /// </summary>
55 
56  /// <summary>
57  /// Structure constructor.
58  /// </summary>
59  /// <param name="timestamp">The timestamp associated to the log message.</param>
60  /// <param name="logMessage">The log message.</param>
61  public Message(long timestamp, ILogMessage logMessage) { Timestamp = timestamp; LogMessage = logMessage; }
62  }
63  }
64 }
A structure describing a log message associated with a timestamp.
long Timestamp
The timestamp associated to the log message.
Base implementation for ILogger.
Definition: Logger.cs:10
override void LogRaw(ILogMessage logMessage)
Internal method used to log a message. All Info, Debug, Error...etc. methods are calling this method...
LogMessageType
Type of a LogMessage.
A base log message used by the logging infrastructure.
Definition: LogMessage.cs:13
Message(long timestamp, ILogMessage logMessage)
Structure constructor.
The base interface for log messages used by the logging infrastructure.
Definition: ILogMessage.cs:8
A logger that stores messages locally with their timestamp, useful for internal log scenarios...
TimestampLocalLogger(DateTime startTime, string moduleName=null)
Initializes a new instance of the LoggerResult class.