Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tracing/3.2/Logger.cs @ 1762

Last change on this file since 1762 was 1622, checked in by epitzer, 16 years ago

Rename config property to adhere to coding conventions. (#524)

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