Lean  $LEAN_TAG$
ILogHandlerExtensions.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 using System;
17 using System.Globalization;
18 
19 namespace QuantConnect.Logging
20 {
21  /// <summary>
22  /// Logging extensions.
23  /// </summary>
24  public static class LogHandlerExtensions
25  {
26  /// <summary>
27  /// Write error message to log
28  /// </summary>
29  /// <param name="logHandler"></param>
30  /// <param name="text">Message</param>
31  /// <param name="args">Arguments to format.</param>
32  public static void Error(this ILogHandler logHandler, string text, params object[] args)
33  {
34  if (logHandler == null)
35  {
36  throw new ArgumentNullException(nameof(logHandler), "Log Handler cannot be null");
37  }
38 
39  logHandler.Error(string.Format(CultureInfo.InvariantCulture, text, args));
40  }
41 
42  /// <summary>
43  /// Write debug message to log
44  /// </summary>
45  /// <param name="logHandler"></param>
46  /// <param name="text">Message</param>
47  /// <param name="args">Arguments to format.</param>
48  public static void Debug(this ILogHandler logHandler, string text, params object[] args)
49  {
50  if (logHandler == null)
51  {
52  throw new ArgumentNullException(nameof(logHandler), "Log Handler cannot be null");
53  }
54 
55  logHandler.Debug(string.Format(CultureInfo.InvariantCulture, text, args));
56  }
57 
58  /// <summary>
59  /// Write debug message to log
60  /// </summary>
61  /// <param name="logHandler"></param>
62  /// <param name="text">Message</param>
63  /// <param name="args">Arguments to format.</param>
64  public static void Trace(this ILogHandler logHandler, string text, params object[] args)
65  {
66  if (logHandler == null)
67  {
68  throw new ArgumentNullException(nameof(logHandler), "Log Handler cannot be null");
69  }
70 
71  logHandler.Trace(string.Format(CultureInfo.InvariantCulture, text, args));
72  }
73  }
74 }