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