Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PluginInfrastructure Refactoring/HeuristicLab.Tracing/3.2/HiveLogger.cs @ 2587

Last change on this file since 2587 was 2587, checked in by gkronber, 14 years ago

Fixed projects to work with new plugin infrastructure. #799

File size: 3.7 KB
Line 
1using System;
2using HeuristicLab.Tracing.Properties;
3using log4net;
4using System.Diagnostics;
5using log4net.Config;
6using System.IO;
7
8namespace HeuristicLab.Tracing {
9  public class HiveLogger {
10    protected static bool IsConfigured = false;
11    protected static void Configure() {
12      if (IsConfigured) return;
13      IsConfigured = true;
14      if (string.IsNullOrEmpty(Settings.Default.TracingLog4netConfigFile)) {
15        Settings.Default.TracingLog4netConfigFile =
16            "HeuristicLab.Hive.log4net.xml";
17      }
18      XmlConfigurator.ConfigureAndWatch(
19        new FileInfo(Settings.Default.TracingLog4netConfigFile));
20      Info("Hive Logging initialized " + DateTime.Now);
21    }
22
23    public static ILog GetDefaultLogger(int nParents) {
24      Configure();
25      StackFrame frame = new StackFrame(nParents + 1);
26      return LogManager.GetLogger(frame.GetMethod().DeclaringType);
27    }
28
29    public static ILog GetDefaultLogger() {
30      Configure();
31      StackFrame frame = new StackFrame(1);
32      return LogManager.GetLogger(frame.GetMethod().DeclaringType);
33    }
34
35    public static void Debug(object message) {
36      GetDefaultLogger(1).Debug(message);
37    }
38
39    public static void Info(object message) {
40      GetDefaultLogger(1).Info(message);
41    }
42
43    public static void Warn(object message) {
44      GetDefaultLogger(1).Warn(message);
45    }
46
47    public static void Error(object message) {
48      GetDefaultLogger(1).Error(message);
49    }
50
51    public static void Fatal(object message) {
52      GetDefaultLogger(1).Fatal(message);
53    }
54
55    public static void Debug(Type type, object message) {
56      Configure();
57      LogManager.GetLogger(type).Debug(message);
58    }
59
60    public static void Info(Type type, object message) {
61      Configure();
62      LogManager.GetLogger(type).Info(message);
63    }
64
65    public static void Warn(Type type, object message) {
66      Configure();
67      LogManager.GetLogger(type).Warn(message);
68    }
69
70    public static void Error(Type type, object message) {
71      Configure();
72      LogManager.GetLogger(type).Error(message);
73    }
74
75    public static void Fatal(Type type, object message) {
76      Configure();
77      LogManager.GetLogger(type).Fatal(message);
78    }
79
80    public static void Debug(object message, Exception exception) {
81      GetDefaultLogger(1).Debug(message, exception);
82    }
83
84    public static void Info(object message, Exception exception) {
85      GetDefaultLogger(1).Info(message, exception);
86    }
87
88    public static void Warn(object message, Exception exception) {
89      GetDefaultLogger(1).Warn(message, exception);
90    }
91
92    public static void Error(object message, Exception exception) {
93      GetDefaultLogger(1).Error(message, exception);
94    }
95
96    public static void Fatal(object message, Exception exception) {
97      GetDefaultLogger(1).Fatal(message, exception);
98    }
99
100    public static void Debug(Type type, object message, Exception exception) {
101      Configure();
102      LogManager.GetLogger(type).Debug(message, exception);
103    }
104
105    public static void Info(Type type, object message, Exception exception) {
106      Configure();
107      LogManager.GetLogger(type).Info(message, exception);
108    }
109
110    public static void Warn(Type type, object message, Exception exception) {
111      Configure();
112      LogManager.GetLogger(type).Warn(message, exception);
113    }
114
115    public static void Error(Type type, object message, Exception exception) {
116      Configure();
117      LogManager.GetLogger(type).Error(message, exception);
118    }
119
120    public static void Fatal(Type type, object message, Exception exception) {
121      Configure();
122      LogManager.GetLogger(type).Fatal(message, exception);
123    }
124
125  }
126}
Note: See TracBrowser for help on using the repository browser.