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