Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tracing/3.3/Logger.cs @ 11845

Last change on this file since 11845 was 11171, checked in by ascheibe, 10 years ago

#2115 merged r11170 (copyright update) into trunk

File size: 6.7 KB
RevLine 
[2645]1#region License Information
2/* HeuristicLab
[11171]3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2645]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
[6173]22
[2645]23using System;
[4068]24using System.Diagnostics;
[1467]25namespace HeuristicLab.Tracing {
26
[3057]27  /// <summary>
[6173]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.
[3057]31  /// </summary>
[1467]32  public class Logger {
33
[3057]34    /// <summary>
[6173]35    /// Issues a debug message.
[3057]36    /// </summary>
37    /// <param name="message">The message.</param>
[1467]38    public static void Debug(object message) {
[6173]39      StackFrame frame = new StackFrame(1);
[6179]40      Trace.TraceInformation("{0} - {1}", frame.GetMethod().DeclaringType, message);
[1467]41    }
42
[3057]43    /// <summary>
[6173]44    /// Issues an informational message.
[3057]45    /// </summary>
46    /// <param name="message">The message.</param>
[1467]47    public static void Info(object message) {
[6173]48      StackFrame frame = new StackFrame(1);
[6179]49      Trace.TraceInformation("{0} - {1}", frame.GetMethod().DeclaringType, message);
[1467]50    }
51
[3057]52    /// <summary>
[6173]53    /// Issues a warning message.
[3057]54    /// </summary>
55    /// <param name="message">The message.</param>
[1467]56    public static void Warn(object message) {
[6173]57      StackFrame frame = new StackFrame(1);
[6179]58      Trace.TraceWarning("{0} - {1}", frame.GetMethod().DeclaringType, message);
[1467]59    }
60
[3057]61    /// <summary>
[6173]62    /// Issues an error message.
[3057]63    /// </summary>
64    /// <param name="message">The message.</param>
[2591]65    public static void Error(object message) {
[6173]66      StackFrame frame = new StackFrame(1);
[6179]67      Trace.TraceError("{0} - {1}", frame.GetMethod().DeclaringType, message);
[1467]68    }
69
[3057]70    /// <summary>
[6173]71    /// Issues a debug message of the specified type.
[3057]72    /// </summary>
73    /// <param name="type">The type.</param>
74    /// <param name="message">The message.</param>
[1467]75    public static void Debug(Type type, object message) {
[6179]76      Trace.TraceInformation("{0}: {1}", type, message);
[1467]77    }
78
[3057]79    /// <summary>
[6173]80    /// Issues an informational message of the specified type.
[3057]81    /// </summary>
82    /// <param name="type">The type.</param>
83    /// <param name="message">The message.</param>
[1467]84    public static void Info(Type type, object message) {
[6179]85      Trace.TraceInformation("{0}: {1}", type, message);
[1467]86    }
87
[3057]88    /// <summary>
[6173]89    /// Issues a warning message of the specified type.
[3057]90    /// </summary>
91    /// <param name="type">The type.</param>
92    /// <param name="message">The message.</param>
[1467]93    public static void Warn(Type type, object message) {
[6179]94      Trace.TraceWarning("{0}: {1}", type, message);
[1467]95    }
96
[3057]97    /// <summary>
[6173]98    /// Issues an error message of the specified type.
[3057]99    /// </summary>
100    /// <param name="type">The type.</param>
101    /// <param name="message">The message.</param>
[1467]102    public static void Error(Type type, object message) {
[6179]103      Trace.TraceError("{0}: {1}", type, message);
[1467]104    }
105
[3057]106    /// <summary>
[6173]107    /// Issues a debug message including an exception.
[3057]108    /// </summary>
109    /// <param name="message">The message.</param>
110    /// <param name="exception">The exception.</param>
[1473]111    public static void Debug(object message, Exception exception) {
[6179]112      Trace.TraceInformation("{0}: {1}:", message, exception);
[1473]113    }
114
[3057]115    /// <summary>
[6173]116    /// Issues an informational message including an exception.
[3057]117    /// </summary>
118    /// <param name="message">The message.</param>
[6173]119    /// <param name="exception">The exception.</param>       
[1473]120    public static void Info(object message, Exception exception) {
[6179]121      Trace.TraceInformation("{0}: {1}:", message, exception);
[1473]122    }
123
[3057]124    /// <summary>
[6173]125    /// Issues a warning message including an exception.
[3057]126    /// </summary>
127    /// <param name="message">The message.</param>
128    /// <param name="exception">The exception.</param>
[1473]129    public static void Warn(object message, Exception exception) {
[6179]130      Trace.TraceWarning("{0}: {1}:", message, exception);
[1473]131    }
132
[3057]133    /// <summary>
[6173]134    /// Issues an error message including an exception.
[3057]135    /// </summary>
136    /// <param name="message">The message.</param>
137    /// <param name="exception">The exception.</param>
[1473]138    public static void Error(object message, Exception exception) {
[6179]139      Trace.TraceError("{0}: {1}:", message, exception);
[1473]140    }
141
[3057]142    /// <summary>
[6173]143    /// Issues a debug message of the specified type including an exception.
[3057]144    /// </summary>
145    /// <param name="type">The type.</param>
146    /// <param name="message">The message.</param>
147    /// <param name="exception">The exception.</param>
[1473]148    public static void Debug(Type type, object message, Exception exception) {
[6179]149      Trace.TraceInformation("{0}: {1}: {2}", type, message, exception);
[1473]150    }
151
[3057]152    /// <summary>
[6173]153    /// Issues an informational message of the specified type including an exception.
[3057]154    /// </summary>
155    /// <param name="type">The type.</param>
156    /// <param name="message">The message.</param>
157    /// <param name="exception">The exception.</param>
[1473]158    public static void Info(Type type, object message, Exception exception) {
[6179]159      Trace.TraceInformation("{0}: {1}: {2}", type, message, exception);
[1473]160    }
161
[3057]162    /// <summary>
[6173]163    /// Issues a warning message of the specified type including an exception.
[3057]164    /// </summary>
165    /// <param name="type">The type.</param>
166    /// <param name="message">The message.</param>
167    /// <param name="exception">The exception.</param>
[1473]168    public static void Warn(Type type, object message, Exception exception) {
[6179]169      Trace.TraceWarning("{0}: {1}: {2}", type, message, exception);
[1473]170    }
171
[3057]172    /// <summary>
[6173]173    /// Issues an error message of the specified type including an exception.
[3057]174    /// </summary>
175    /// <param name="type">The type.</param>
176    /// <param name="message">The message.</param>
177    /// <param name="exception">The exception.</param>
[1473]178    public static void Error(Type type, object message, Exception exception) {
[6179]179      Trace.TraceError("{0}: {1}: {2}", type, message, exception);
[1473]180    }
[1467]181  }
182}
Note: See TracBrowser for help on using the repository browser.