[1467] | 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 |
|
---|
| 10 | public class Logger {
|
---|
| 11 |
|
---|
[1931] | 12 | protected static bool IsConfigured = false;
|
---|
[1467] | 13 |
|
---|
[1933] | 14 | protected static void Configure() {
|
---|
[1467] | 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 | }
|
---|