Applied patch from Jan Limpens 'ReflectionBasedDictionaryAdapter needs to check if...
[castle.git] / Services / Logging / Castle.Services.Logging.log4netIntegration / Log4netLogger.cs
blobd2970ed36ff0424d5308a2fc5585e905fef7b7b4
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 using Logger = Castle.Core.Logging.ILogger;
17 namespace Castle.Services.Logging.Log4netIntegration
19 using System;
20 using log4net;
21 using log4net.Core;
23 [Serializable]
24 public class Log4netLogger : MarshalByRefObject, Logger
26 private static Type declaringType = typeof(Log4netLogger);
28 private ILogger logger;
29 private Log4netFactory factory;
31 internal Log4netLogger()
35 internal Log4netLogger(ILog log, Log4netFactory factory) : this(log.Logger, factory)
39 public Log4netLogger(ILogger logger, Log4netFactory factory)
41 Logger = logger;
42 Factory = factory;
45 public virtual Logger CreateChildLogger(String name)
47 return Factory.Create(Logger.Name + "." + name);
50 protected internal ILogger Logger
52 get { return logger; }
53 set { logger = value; }
56 protected internal Log4netFactory Factory
58 get { return factory; }
59 set { factory = value; }
62 public override string ToString()
64 return Logger.ToString();
67 #region Debug
69 public void Debug(String message)
71 if (IsDebugEnabled)
73 Logger.Log(declaringType, Level.Debug, message, null);
77 public void Debug(String message, Exception exception)
79 if (IsDebugEnabled)
81 Logger.Log(declaringType, Level.Debug, message, exception);
85 public void DebugFormat(String format, params Object[] args)
87 if (IsDebugEnabled)
89 Logger.Log(declaringType, Level.Debug, String.Format(format, args), null);
93 public void DebugFormat(Exception exception, String format, params Object[] args)
95 if (IsDebugEnabled)
97 Logger.Log(declaringType, Level.Debug, String.Format(format, args), exception);
101 public void DebugFormat(IFormatProvider formatProvider, String format, params Object[] args)
103 if (IsDebugEnabled)
105 Logger.Log(declaringType, Level.Debug, String.Format(formatProvider, format, args), null);
109 public void DebugFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args)
111 if (IsDebugEnabled)
113 Logger.Log(declaringType, Level.Debug, String.Format(formatProvider, format, args), exception);
117 [Obsolete("Use DebugFormat instead")]
118 public void Debug(String format, params object[] args)
120 if (IsDebugEnabled)
122 Logger.Log(declaringType, Level.Debug, String.Format(format, args), null);
126 #endregion
128 #region Info
130 public void Info(String message)
132 if (IsInfoEnabled)
134 Logger.Log(declaringType, Level.Info, message, null);
138 public void Info(String message, Exception exception)
140 if (IsInfoEnabled)
142 Logger.Log(declaringType, Level.Info, message, exception);
146 public void InfoFormat(String format, params Object[] args)
148 if (IsInfoEnabled)
150 Logger.Log(declaringType, Level.Info, String.Format(format, args), null);
154 public void InfoFormat(Exception exception, String format, params Object[] args)
156 if (IsInfoEnabled)
158 Logger.Log(declaringType, Level.Info, String.Format(format, args), exception);
162 public void InfoFormat(IFormatProvider formatProvider, String format, params Object[] args)
164 if (IsInfoEnabled)
166 Logger.Log(declaringType, Level.Info, String.Format(formatProvider, format, args), null);
170 public void InfoFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args)
172 if (IsInfoEnabled)
174 Logger.Log(declaringType, Level.Info, String.Format(formatProvider, format, args), exception);
178 [Obsolete("Use InfoFormat instead")]
179 public void Info(String format, params object[] args)
181 if (IsInfoEnabled)
183 Logger.Log(declaringType, Level.Info, String.Format(format, args), null);
187 #endregion
189 #region Warn
191 public void Warn(String message)
193 if (IsWarnEnabled)
195 Logger.Log(declaringType, Level.Warn, message, null);
199 public void Warn(String message, Exception exception)
201 if (IsWarnEnabled)
203 Logger.Log(declaringType, Level.Warn, message, exception);
207 public void WarnFormat(String format, params Object[] args)
209 if (IsWarnEnabled)
211 Logger.Log(declaringType, Level.Warn, String.Format(format, args), null);
215 public void WarnFormat(Exception exception, String format, params Object[] args)
217 if (IsWarnEnabled)
219 Logger.Log(declaringType, Level.Warn, String.Format(format, args), exception);
223 public void WarnFormat(IFormatProvider formatProvider, String format, params Object[] args)
225 if (IsWarnEnabled)
227 Logger.Log(declaringType, Level.Warn, String.Format(formatProvider, format, args), null);
231 public void WarnFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args)
233 if (IsWarnEnabled)
235 Logger.Log(declaringType, Level.Warn, String.Format(formatProvider, format, args), exception);
239 [Obsolete("Use WarnFormat instead")]
240 public void Warn(String format, params object[] args)
242 if (IsWarnEnabled)
244 Logger.Log(declaringType, Level.Warn, String.Format(format, args), null);
248 #endregion
250 #region Error
252 public void Error(String message)
254 if (IsErrorEnabled)
256 Logger.Log(declaringType, Level.Error, message, null);
260 public void Error(String message, Exception exception)
262 if (IsErrorEnabled)
264 Logger.Log(declaringType, Level.Error, message, exception);
268 public void ErrorFormat(String format, params Object[] args)
270 if (IsErrorEnabled)
272 Logger.Log(declaringType, Level.Error, String.Format(format, args), null);
276 public void ErrorFormat(Exception exception, String format, params Object[] args)
278 if (IsErrorEnabled)
280 Logger.Log(declaringType, Level.Error, String.Format(format, args), exception);
284 public void ErrorFormat(IFormatProvider formatProvider, String format, params Object[] args)
286 if (IsErrorEnabled)
288 Logger.Log(declaringType, Level.Error, String.Format(formatProvider, format, args), null);
292 public void ErrorFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args)
294 if (IsErrorEnabled)
296 Logger.Log(declaringType, Level.Error, String.Format(formatProvider, format, args), exception);
300 [Obsolete("Use ErrorFormat instead")]
301 public void Error(String format, params object[] args)
303 if (IsErrorEnabled)
305 Logger.Log(declaringType, Level.Error, String.Format(format, args), null);
309 #endregion
311 #region Fatal
313 public void Fatal(String message)
315 if (IsFatalEnabled)
317 Logger.Log(declaringType, Level.Fatal, message, null);
321 public void Fatal(String message, Exception exception)
323 if (IsFatalEnabled)
325 Logger.Log(declaringType, Level.Fatal, message, exception);
329 public void FatalFormat(String format, params Object[] args)
331 if (IsFatalEnabled)
333 Logger.Log(declaringType, Level.Fatal, String.Format(format, args), null);
337 public void FatalFormat(Exception exception, String format, params Object[] args)
339 if (IsFatalEnabled)
341 Logger.Log(declaringType, Level.Fatal, String.Format(format, args), exception);
345 public void FatalFormat(IFormatProvider formatProvider, String format, params Object[] args)
347 if (IsFatalEnabled)
349 Logger.Log(declaringType, Level.Fatal, String.Format(formatProvider, format, args), null);
353 public void FatalFormat(Exception exception, IFormatProvider formatProvider, String format, params Object[] args)
355 if (IsFatalEnabled)
357 Logger.Log(declaringType, Level.Fatal, String.Format(formatProvider, format, args), exception);
361 [Obsolete("Use FatalFormat instead")]
362 public void Fatal(String format, params object[] args)
364 if (IsFatalEnabled)
366 Logger.Log(declaringType, Level.Fatal, String.Format(format, args), null);
370 #endregion
372 #region FatalError (obsolete)
374 [Obsolete("Use FatalFormat instead")]
375 public void FatalError(String format, params object[] args)
377 if (IsFatalErrorEnabled)
379 Logger.Log(declaringType, Level.Fatal, String.Format(format, args), null);
383 [Obsolete("Use Fatal instead")]
384 public void FatalError(String message, Exception exception)
386 if (IsFatalErrorEnabled)
388 Logger.Log(declaringType, Level.Fatal, message, exception);
392 [Obsolete("Use Fatal instead")]
393 public void FatalError(String message)
395 if (IsFatalErrorEnabled)
397 Logger.Log(declaringType, Level.Fatal, message, null);
401 #endregion
403 #region Is (...) Enabled
405 public bool IsErrorEnabled
407 get { return Logger.IsEnabledFor(Level.Error); }
410 public bool IsWarnEnabled
412 get { return Logger.IsEnabledFor(Level.Warn); }
415 public bool IsDebugEnabled
417 get { return Logger.IsEnabledFor(Level.Debug); }
420 public bool IsFatalEnabled
422 get { return Logger.IsEnabledFor(Level.Fatal); }
425 [Obsolete("Use IsFatalEnabled instead")]
426 public bool IsFatalErrorEnabled
428 get { return Logger.IsEnabledFor(Level.Fatal); }
431 public bool IsInfoEnabled
433 get { return Logger.IsEnabledFor(Level.Info); }
436 #endregion