Lean  $LEAN_TAG$
LogEntry.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15 */
16 
17 using System;
18 using System.Globalization;
19 
20 namespace QuantConnect.Logging
21 {
22  /// <summary>
23  /// Log entry wrapper to make logging simpler:
24  /// </summary>
25  public class LogEntry
26  {
27  /// <summary>
28  /// Time of the log entry
29  /// </summary>
30  public DateTime Time;
31 
32  /// <summary>
33  /// Message of the log entry
34  /// </summary>
35  public string Message;
36 
37  /// <summary>
38  /// Descriptor of the message type.
39  /// </summary>
41 
42  /// <summary>
43  /// Create a default log message with the current time.
44  /// </summary>
45  /// <param name="message"></param>
46  public LogEntry(string message)
47  {
48  Time = DateTime.UtcNow;
49  Message = message;
50  MessageType = LogType.Trace;
51  }
52 
53  /// <summary>
54  /// Create a log entry at a specific time in the analysis (for a backtest).
55  /// </summary>
56  /// <param name="message">Message for log</param>
57  /// <param name="time">Utc time of the message</param>
58  /// <param name="type">Type of the log entry</param>
59  public LogEntry(string message, DateTime time, LogType type = LogType.Trace)
60  {
61  Time = time;
62  Message = message;
63  MessageType = type;
64  }
65 
66  /// <summary>
67  /// Helper override on the log entry.
68  /// </summary>
69  /// <returns></returns>
70  public override string ToString()
71  {
72  return $"{Time.ToString("o", CultureInfo.InvariantCulture)} {MessageType} {Message}";
73  }
74  }
75 }