Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.Tracing/3.2/Logger.cs @ 3528

Last change on this file since 3528 was 2744, checked in by epitzer, 15 years ago

update to new PluginInfrastructure (#802)

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