1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
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
)
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();
69 public void Debug(String message
)
73 Logger
.Log(declaringType
, Level
.Debug
, message
, null);
77 public void Debug(String message
, Exception exception
)
81 Logger
.Log(declaringType
, Level
.Debug
, message
, exception
);
85 public void DebugFormat(String format
, params Object
[] args
)
89 Logger
.Log(declaringType
, Level
.Debug
, String
.Format(format
, args
), null);
93 public void DebugFormat(Exception exception
, String format
, params Object
[] args
)
97 Logger
.Log(declaringType
, Level
.Debug
, String
.Format(format
, args
), exception
);
101 public void DebugFormat(IFormatProvider formatProvider
, String format
, params Object
[] args
)
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
)
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
)
122 Logger
.Log(declaringType
, Level
.Debug
, String
.Format(format
, args
), null);
130 public void Info(String message
)
134 Logger
.Log(declaringType
, Level
.Info
, message
, null);
138 public void Info(String message
, Exception exception
)
142 Logger
.Log(declaringType
, Level
.Info
, message
, exception
);
146 public void InfoFormat(String format
, params Object
[] args
)
150 Logger
.Log(declaringType
, Level
.Info
, String
.Format(format
, args
), null);
154 public void InfoFormat(Exception exception
, String format
, params Object
[] args
)
158 Logger
.Log(declaringType
, Level
.Info
, String
.Format(format
, args
), exception
);
162 public void InfoFormat(IFormatProvider formatProvider
, String format
, params Object
[] args
)
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
)
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
)
183 Logger
.Log(declaringType
, Level
.Info
, String
.Format(format
, args
), null);
191 public void Warn(String message
)
195 Logger
.Log(declaringType
, Level
.Warn
, message
, null);
199 public void Warn(String message
, Exception exception
)
203 Logger
.Log(declaringType
, Level
.Warn
, message
, exception
);
207 public void WarnFormat(String format
, params Object
[] args
)
211 Logger
.Log(declaringType
, Level
.Warn
, String
.Format(format
, args
), null);
215 public void WarnFormat(Exception exception
, String format
, params Object
[] args
)
219 Logger
.Log(declaringType
, Level
.Warn
, String
.Format(format
, args
), exception
);
223 public void WarnFormat(IFormatProvider formatProvider
, String format
, params Object
[] args
)
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
)
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
)
244 Logger
.Log(declaringType
, Level
.Warn
, String
.Format(format
, args
), null);
252 public void Error(String message
)
256 Logger
.Log(declaringType
, Level
.Error
, message
, null);
260 public void Error(String message
, Exception exception
)
264 Logger
.Log(declaringType
, Level
.Error
, message
, exception
);
268 public void ErrorFormat(String format
, params Object
[] args
)
272 Logger
.Log(declaringType
, Level
.Error
, String
.Format(format
, args
), null);
276 public void ErrorFormat(Exception exception
, String format
, params Object
[] args
)
280 Logger
.Log(declaringType
, Level
.Error
, String
.Format(format
, args
), exception
);
284 public void ErrorFormat(IFormatProvider formatProvider
, String format
, params Object
[] args
)
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
)
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
)
305 Logger
.Log(declaringType
, Level
.Error
, String
.Format(format
, args
), null);
313 public void Fatal(String message
)
317 Logger
.Log(declaringType
, Level
.Fatal
, message
, null);
321 public void Fatal(String message
, Exception exception
)
325 Logger
.Log(declaringType
, Level
.Fatal
, message
, exception
);
329 public void FatalFormat(String format
, params Object
[] args
)
333 Logger
.Log(declaringType
, Level
.Fatal
, String
.Format(format
, args
), null);
337 public void FatalFormat(Exception exception
, String format
, params Object
[] args
)
341 Logger
.Log(declaringType
, Level
.Fatal
, String
.Format(format
, args
), exception
);
345 public void FatalFormat(IFormatProvider formatProvider
, String format
, params Object
[] args
)
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
)
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
)
366 Logger
.Log(declaringType
, Level
.Fatal
, String
.Format(format
, args
), null);
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);
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); }