1 | using System;
|
---|
2 | using HeuristicLab.Tracing.Properties;
|
---|
3 | using log4net;
|
---|
4 | using System.Diagnostics;
|
---|
5 | using log4net.Config;
|
---|
6 | using System.IO;
|
---|
7 |
|
---|
8 | namespace 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 | Path.Combine(
|
---|
17 | PluginInfrastructure.Properties.Settings.Default.PluginDir,
|
---|
18 | "HeuristicLab.Hive.log4net.xml");
|
---|
19 | }
|
---|
20 | XmlConfigurator.ConfigureAndWatch(
|
---|
21 | new FileInfo(Settings.Default.TracingLog4netConfigFile));
|
---|
22 | Info("Hive Logging initialized " + DateTime.Now);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public static ILog GetDefaultLogger(int nParents) {
|
---|
26 | Configure();
|
---|
27 | StackFrame frame = new StackFrame(nParents + 1);
|
---|
28 | return LogManager.GetLogger(frame.GetMethod().DeclaringType);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public static ILog GetDefaultLogger() {
|
---|
32 | Configure();
|
---|
33 | StackFrame frame = new StackFrame(1);
|
---|
34 | return LogManager.GetLogger(frame.GetMethod().DeclaringType);
|
---|
35 | }
|
---|
36 |
|
---|
37 | public static void Debug(object message) {
|
---|
38 | GetDefaultLogger(1).Debug(message);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public static void Info(object message) {
|
---|
42 | GetDefaultLogger(1).Info(message);
|
---|
43 | }
|
---|
44 |
|
---|
45 | public static void Warn(object message) {
|
---|
46 | GetDefaultLogger(1).Warn(message);
|
---|
47 | }
|
---|
48 |
|
---|
49 | public static void Error(object message) {
|
---|
50 | GetDefaultLogger(1).Error(message);
|
---|
51 | }
|
---|
52 |
|
---|
53 | public static void Fatal(object message) {
|
---|
54 | GetDefaultLogger(1).Fatal(message);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public static void Debug(Type type, object message) {
|
---|
58 | Configure();
|
---|
59 | LogManager.GetLogger(type).Debug(message);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public static void Info(Type type, object message) {
|
---|
63 | Configure();
|
---|
64 | LogManager.GetLogger(type).Info(message);
|
---|
65 | }
|
---|
66 |
|
---|
67 | public static void Warn(Type type, object message) {
|
---|
68 | Configure();
|
---|
69 | LogManager.GetLogger(type).Warn(message);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public static void Error(Type type, object message) {
|
---|
73 | Configure();
|
---|
74 | LogManager.GetLogger(type).Error(message);
|
---|
75 | }
|
---|
76 |
|
---|
77 | public static void Fatal(Type type, object message) {
|
---|
78 | Configure();
|
---|
79 | LogManager.GetLogger(type).Fatal(message);
|
---|
80 | }
|
---|
81 |
|
---|
82 | public static void Debug(object message, Exception exception) {
|
---|
83 | GetDefaultLogger(1).Debug(message, exception);
|
---|
84 | }
|
---|
85 |
|
---|
86 | public static void Info(object message, Exception exception) {
|
---|
87 | GetDefaultLogger(1).Info(message, exception);
|
---|
88 | }
|
---|
89 |
|
---|
90 | public static void Warn(object message, Exception exception) {
|
---|
91 | GetDefaultLogger(1).Warn(message, exception);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public static void Error(object message, Exception exception) {
|
---|
95 | GetDefaultLogger(1).Error(message, exception);
|
---|
96 | }
|
---|
97 |
|
---|
98 | public static void Fatal(object message, Exception exception) {
|
---|
99 | GetDefaultLogger(1).Fatal(message, exception);
|
---|
100 | }
|
---|
101 |
|
---|
102 | public static void Debug(Type type, object message, Exception exception) {
|
---|
103 | Configure();
|
---|
104 | LogManager.GetLogger(type).Debug(message, exception);
|
---|
105 | }
|
---|
106 |
|
---|
107 | public static void Info(Type type, object message, Exception exception) {
|
---|
108 | Configure();
|
---|
109 | LogManager.GetLogger(type).Info(message, exception);
|
---|
110 | }
|
---|
111 |
|
---|
112 | public static void Warn(Type type, object message, Exception exception) {
|
---|
113 | Configure();
|
---|
114 | LogManager.GetLogger(type).Warn(message, exception);
|
---|
115 | }
|
---|
116 |
|
---|
117 | public static void Error(Type type, object message, Exception exception) {
|
---|
118 | Configure();
|
---|
119 | LogManager.GetLogger(type).Error(message, exception);
|
---|
120 | }
|
---|
121 |
|
---|
122 | public static void Fatal(Type type, object message, Exception exception) {
|
---|
123 | Configure();
|
---|
124 | LogManager.GetLogger(type).Fatal(message, exception);
|
---|
125 | }
|
---|
126 |
|
---|
127 | }
|
---|
128 | }
|
---|