Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Tracing/3.3/Logger.cs @ 12546

Last change on this file since 12546 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 6.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22
23using System;
24using System.Diagnostics;
25namespace HeuristicLab.Tracing {
26
27  /// <summary>
28  /// HeuristicLab.Tracing using System.Diagnostics.Trace.
29  /// Note that tracing is only activated if the DEBUG or TRACE symbol is set.
30  /// Configuration (type of listener, file name, ...) is done in app.config in the <system.diagnostics> section.
31  /// </summary>
32  public class Logger {
33
34    /// <summary>
35    /// Issues a debug message.
36    /// </summary>
37    /// <param name="message">The message.</param>
38    public static void Debug(object message) {
39      StackFrame frame = new StackFrame(1);
40      Trace.TraceInformation("{0} - {1}", frame.GetMethod().DeclaringType, message);
41    }
42
43    /// <summary>
44    /// Issues an informational message.
45    /// </summary>
46    /// <param name="message">The message.</param>
47    public static void Info(object message) {
48      StackFrame frame = new StackFrame(1);
49      Trace.TraceInformation("{0} - {1}", frame.GetMethod().DeclaringType, message);
50    }
51
52    /// <summary>
53    /// Issues a warning message.
54    /// </summary>
55    /// <param name="message">The message.</param>
56    public static void Warn(object message) {
57      StackFrame frame = new StackFrame(1);
58      Trace.TraceWarning("{0} - {1}", frame.GetMethod().DeclaringType, message);
59    }
60
61    /// <summary>
62    /// Issues an error message.
63    /// </summary>
64    /// <param name="message">The message.</param>
65    public static void Error(object message) {
66      StackFrame frame = new StackFrame(1);
67      Trace.TraceError("{0} - {1}", frame.GetMethod().DeclaringType, message);
68    }
69
70    /// <summary>
71    /// Issues a debug message of the specified type.
72    /// </summary>
73    /// <param name="type">The type.</param>
74    /// <param name="message">The message.</param>
75    public static void Debug(Type type, object message) {
76      Trace.TraceInformation("{0}: {1}", type, message);
77    }
78
79    /// <summary>
80    /// Issues an informational message of the specified type.
81    /// </summary>
82    /// <param name="type">The type.</param>
83    /// <param name="message">The message.</param>
84    public static void Info(Type type, object message) {
85      Trace.TraceInformation("{0}: {1}", type, message);
86    }
87
88    /// <summary>
89    /// Issues a warning message of the specified type.
90    /// </summary>
91    /// <param name="type">The type.</param>
92    /// <param name="message">The message.</param>
93    public static void Warn(Type type, object message) {
94      Trace.TraceWarning("{0}: {1}", type, message);
95    }
96
97    /// <summary>
98    /// Issues an error message of the specified type.
99    /// </summary>
100    /// <param name="type">The type.</param>
101    /// <param name="message">The message.</param>
102    public static void Error(Type type, object message) {
103      Trace.TraceError("{0}: {1}", type, message);
104    }
105
106    /// <summary>
107    /// Issues a debug message including an exception.
108    /// </summary>
109    /// <param name="message">The message.</param>
110    /// <param name="exception">The exception.</param>
111    public static void Debug(object message, Exception exception) {
112      Trace.TraceInformation("{0}: {1}:", message, exception);
113    }
114
115    /// <summary>
116    /// Issues an informational message including an exception.
117    /// </summary>
118    /// <param name="message">The message.</param>
119    /// <param name="exception">The exception.</param>       
120    public static void Info(object message, Exception exception) {
121      Trace.TraceInformation("{0}: {1}:", message, exception);
122    }
123
124    /// <summary>
125    /// Issues a warning message including an exception.
126    /// </summary>
127    /// <param name="message">The message.</param>
128    /// <param name="exception">The exception.</param>
129    public static void Warn(object message, Exception exception) {
130      Trace.TraceWarning("{0}: {1}:", message, exception);
131    }
132
133    /// <summary>
134    /// Issues an error message including an exception.
135    /// </summary>
136    /// <param name="message">The message.</param>
137    /// <param name="exception">The exception.</param>
138    public static void Error(object message, Exception exception) {
139      Trace.TraceError("{0}: {1}:", message, exception);
140    }
141
142    /// <summary>
143    /// Issues a debug message of the specified type including an exception.
144    /// </summary>
145    /// <param name="type">The type.</param>
146    /// <param name="message">The message.</param>
147    /// <param name="exception">The exception.</param>
148    public static void Debug(Type type, object message, Exception exception) {
149      Trace.TraceInformation("{0}: {1}: {2}", type, message, exception);
150    }
151
152    /// <summary>
153    /// Issues an informational message of the specified type including an exception.
154    /// </summary>
155    /// <param name="type">The type.</param>
156    /// <param name="message">The message.</param>
157    /// <param name="exception">The exception.</param>
158    public static void Info(Type type, object message, Exception exception) {
159      Trace.TraceInformation("{0}: {1}: {2}", type, message, exception);
160    }
161
162    /// <summary>
163    /// Issues a warning message of the specified type including an exception.
164    /// </summary>
165    /// <param name="type">The type.</param>
166    /// <param name="message">The message.</param>
167    /// <param name="exception">The exception.</param>
168    public static void Warn(Type type, object message, Exception exception) {
169      Trace.TraceWarning("{0}: {1}: {2}", type, message, exception);
170    }
171
172    /// <summary>
173    /// Issues an error message of the specified type including an exception.
174    /// </summary>
175    /// <param name="type">The type.</param>
176    /// <param name="message">The message.</param>
177    /// <param name="exception">The exception.</param>
178    public static void Error(Type type, object message, Exception exception) {
179      Trace.TraceError("{0}: {1}: {2}", type, message, exception);
180    }
181  }
182}
Note: See TracBrowser for help on using the repository browser.