Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Tracing/3.3/HiveLogger.cs @ 5534

Last change on this file since 5534 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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
22using System;
23using System.Diagnostics;
24using System.IO;
25using HeuristicLab.Tracing.Properties;
26using log4net;
27using log4net.Config;
28
29namespace HeuristicLab.Tracing {
30  public class HiveLogger {
31    protected static bool IsConfigured = false;
32    protected static void Configure() {
33      if (IsConfigured) return;
34      IsConfigured = true;
35      if (string.IsNullOrEmpty(Settings.Default.TracingLog4netConfigFile)) {
36        Settings.Default.TracingLog4netConfigFile =
37            "HeuristicLab.Hive.log4net.xml";
38      }
39      XmlConfigurator.ConfigureAndWatch(
40        new FileInfo(Settings.Default.TracingLog4netConfigFile));
41      Info("Hive Logging initialized " + DateTime.Now);
42    }
43
44    public static ILog GetDefaultLogger(int nParents) {
45      Configure();
46      StackFrame frame = new StackFrame(nParents + 1);
47      return LogManager.GetLogger(frame.GetMethod().DeclaringType);
48    }
49
50    public static ILog GetDefaultLogger() {
51      Configure();
52      StackFrame frame = new StackFrame(1);
53      return LogManager.GetLogger(frame.GetMethod().DeclaringType);
54    }
55
56    public static void Debug(object message) {
57      GetDefaultLogger(1).Debug(DateTime.Now + ":" + DateTime.Now.Millisecond + " - " + message);
58    }
59
60    public static void Info(object message) {
61      GetDefaultLogger(1).Info(DateTime.Now + ":" + DateTime.Now.Millisecond + " - " + message);
62    }
63
64    public static void Warn(object message) {
65      GetDefaultLogger(1).Warn(DateTime.Now + ":" + DateTime.Now.Millisecond + " - " + message);
66    }
67
68    public static void Error(object message) {
69      GetDefaultLogger(1).Error(DateTime.Now + ":" + DateTime.Now.Millisecond + " - " + message);
70    }
71
72    public static void Fatal(object message) {
73      GetDefaultLogger(1).Fatal(DateTime.Now + ":" + DateTime.Now.Millisecond + " - " + message);
74    }
75
76    public static void Debug(Type type, object message) {
77      Configure();
78      LogManager.GetLogger(type).Debug(message);
79    }
80
81    public static void Info(Type type, object message) {
82      Configure();
83      LogManager.GetLogger(type).Info(message);
84    }
85
86    public static void Warn(Type type, object message) {
87      Configure();
88      LogManager.GetLogger(type).Warn(message);
89    }
90
91    public static void Error(Type type, object message) {
92      Configure();
93      LogManager.GetLogger(type).Error(message);
94    }
95
96    public static void Fatal(Type type, object message) {
97      Configure();
98      LogManager.GetLogger(type).Fatal(message);
99    }
100
101    public static void Debug(object message, Exception exception) {
102      GetDefaultLogger(1).Debug(message, exception);
103    }
104
105    public static void Info(object message, Exception exception) {
106      GetDefaultLogger(1).Info(message, exception);
107    }
108
109    public static void Warn(object message, Exception exception) {
110      GetDefaultLogger(1).Warn(message, exception);
111    }
112
113    public static void Error(object message, Exception exception) {
114      GetDefaultLogger(1).Error(message, exception);
115    }
116
117    public static void Fatal(object message, Exception exception) {
118      GetDefaultLogger(1).Fatal(message, exception);
119    }
120
121    public static void Debug(Type type, object message, Exception exception) {
122      Configure();
123      LogManager.GetLogger(type).Debug(message, exception);
124    }
125
126    public static void Info(Type type, object message, Exception exception) {
127      Configure();
128      LogManager.GetLogger(type).Info(message, exception);
129    }
130
131    public static void Warn(Type type, object message, Exception exception) {
132      Configure();
133      LogManager.GetLogger(type).Warn(message, exception);
134    }
135
136    public static void Error(Type type, object message, Exception exception) {
137      Configure();
138      LogManager.GetLogger(type).Error(message, exception);
139    }
140
141    public static void Fatal(Type type, object message, Exception exception) {
142      Configure();
143      LogManager.GetLogger(type).Fatal(message, exception);
144    }
145
146  }
147}
Note: See TracBrowser for help on using the repository browser.