Moved the place where loggers are named.
[CSharpLibraryStarterKit.git] / src / YOURLIBNAME / Logger.cs
blob2d89e8d53aa3486eaa19821b539c7e37e4757ab0
1 //-----------------------------------------------------------------------
2 // <copyright file="Logger.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
4 // </copyright>
5 //-----------------------------------------------------------------------
7 namespace YOURLIBNAME {
8 using System;
9 using System.Globalization;
10 using log4net.Core;
11 using YOURLIBNAME.Loggers;
13 /// <summary>
14 /// A general logger for the entire YOURLIBNAME library.
15 /// </summary>
16 /// <remarks>
17 /// Because this logger is intended for use with non-localized strings, the
18 /// overloads that take <see cref="CultureInfo"/> have been removed, and
19 /// <see cref="CultureInfo.InvariantCulture"/> is used implicitly.
20 /// </remarks>
21 internal static class Logger {
22 /// <summary>
23 /// The <see cref="ILog"/> instance that is to be used for the duration of the appdomain.
24 /// </summary>
25 private static ILog facade = InitializeFacade();
27 #region ILog Members
28 //// Although this static class doesn't literally implement the ILog interface,
29 //// we implement (mostly) all the same methods in a static way.
31 /// <summary>
32 /// Gets a value indicating whether this logger is enabled for the <see cref="Level.Debug"/> level.
33 /// </summary>
34 /// <value>
35 /// <c>true</c> if this logger is enabled for <see cref="Level.Debug"/> events, <c>false</c> otherwise.
36 /// </value>
37 /// <remarks>
38 /// <para>
39 /// This function is intended to lessen the computational cost of
40 /// disabled log debug statements.
41 /// </para>
42 /// <para> For some ILog interface <c>log</c>, when you write:</para>
43 /// <code lang="C#">
44 /// log.Debug("This is entry number: " + i );
45 /// </code>
46 /// <para>
47 /// You incur the cost constructing the message, string construction and concatenation in
48 /// this case, regardless of whether the message is logged or not.
49 /// </para>
50 /// <para>
51 /// If you are worried about speed (who isn't), then you should write:
52 /// </para>
53 /// <code lang="C#">
54 /// if (log.IsDebugEnabled)
55 /// {
56 /// log.Debug("This is entry number: " + i );
57 /// }
58 /// </code>
59 /// <para>
60 /// This way you will not incur the cost of parameter
61 /// construction if debugging is disabled for <c>log</c>. On
62 /// the other hand, if the <c>log</c> is debug enabled, you
63 /// will incur the cost of evaluating whether the logger is debug
64 /// enabled twice. Once in <see cref="IsDebugEnabled"/> and once in
65 /// the <see cref="Debug(object)"/>. This is an insignificant overhead
66 /// since evaluating a logger takes about 1% of the time it
67 /// takes to actually log. This is the preferred style of logging.
68 /// </para>
69 /// <para>Alternatively if your logger is available statically then the is debug
70 /// enabled state can be stored in a static variable like this:
71 /// </para>
72 /// <code lang="C#">
73 /// private static readonly bool isDebugEnabled = log.IsDebugEnabled;
74 /// </code>
75 /// <para>
76 /// Then when you come to log you can write:
77 /// </para>
78 /// <code lang="C#">
79 /// if (isDebugEnabled)
80 /// {
81 /// log.Debug("This is entry number: " + i );
82 /// }
83 /// </code>
84 /// <para>
85 /// This way the debug enabled state is only queried once
86 /// when the class is loaded. Using a <c>private static readonly</c>
87 /// variable is the most efficient because it is a run time constant
88 /// and can be heavily optimized by the JIT compiler.
89 /// </para>
90 /// <para>
91 /// Of course if you use a static readonly variable to
92 /// hold the enabled state of the logger then you cannot
93 /// change the enabled state at runtime to vary the logging
94 /// that is produced. You have to decide if you need absolute
95 /// speed or runtime flexibility.
96 /// </para>
97 /// </remarks>
98 /// <seealso cref="Debug(object)"/>
99 /// <seealso cref="DebugFormat(string, object[])"/>
100 public static bool IsDebugEnabled {
101 get { return facade.IsDebugEnabled; }
104 /// <summary>
105 /// Gets a value indicating whether this logger is enabled for the <see cref="Level.Info"/> level.
106 /// </summary>
107 /// <value>
108 /// <c>true</c> if this logger is enabled for <see cref="Level.Info"/> events, <c>false</c> otherwise.
109 /// </value>
110 /// <remarks>
111 /// For more information see <see cref="ILog.IsDebugEnabled"/>.
112 /// </remarks>
113 /// <seealso cref="Info(object)"/>
114 /// <seealso cref="InfoFormat(string, object[])"/>
115 /// <seealso cref="ILog.IsDebugEnabled"/>
116 public static bool IsInfoEnabled {
117 get { return facade.IsInfoEnabled; }
120 /// <summary>
121 /// Gets a value indicating whether this logger is enabled for the <see cref="Level.Warn"/> level.
122 /// </summary>
123 /// <value>
124 /// <c>true</c> if this logger is enabled for <see cref="Level.Warn"/> events, <c>false</c> otherwise.
125 /// </value>
126 /// <remarks>
127 /// For more information see <see cref="ILog.IsDebugEnabled"/>.
128 /// </remarks>
129 /// <seealso cref="Warn(object)"/>
130 /// <seealso cref="WarnFormat(string, object[])"/>
131 /// <seealso cref="ILog.IsDebugEnabled"/>
132 public static bool IsWarnEnabled {
133 get { return facade.IsWarnEnabled; }
136 /// <summary>
137 /// Gets a value indicating whether this logger is enabled for the <see cref="Level.Error"/> level.
138 /// </summary>
139 /// <value>
140 /// <c>true</c> if this logger is enabled for <see cref="Level.Error"/> events, <c>false</c> otherwise.
141 /// </value>
142 /// <remarks>
143 /// For more information see <see cref="ILog.IsDebugEnabled"/>.
144 /// </remarks>
145 /// <seealso cref="Error(object)"/>
146 /// <seealso cref="ErrorFormat(string, object[])"/>
147 /// <seealso cref="ILog.IsDebugEnabled"/>
148 public static bool IsErrorEnabled {
149 get { return facade.IsErrorEnabled; }
152 /// <summary>
153 /// Gets a value indicating whether this logger is enabled for the <see cref="Level.Fatal"/> level.
154 /// </summary>
155 /// <value>
156 /// <c>true</c> if this logger is enabled for <see cref="Level.Fatal"/> events, <c>false</c> otherwise.
157 /// </value>
158 /// <remarks>
159 /// For more information see <see cref="ILog.IsDebugEnabled"/>.
160 /// </remarks>
161 /// <seealso cref="Fatal(object)"/>
162 /// <seealso cref="FatalFormat(string, object[])"/>
163 /// <seealso cref="ILog.IsDebugEnabled"/>
164 public static bool IsFatalEnabled {
165 get { return facade.IsFatalEnabled; }
168 /// <overloads>Log a message object with the <see cref="Level.Debug"/> level.</overloads>
169 /// <summary>
170 /// Log a message object with the <see cref="Level.Debug"/> level.
171 /// </summary>
172 /// <param name="message">The message object to log.</param>
173 /// <remarks>
174 /// <para>
175 /// This method first checks if this logger is <c>DEBUG</c>
176 /// enabled by comparing the level of this logger with the
177 /// <see cref="Level.Debug"/> level. If this logger is
178 /// <c>DEBUG</c> enabled, then it converts the message object
179 /// (passed as parameter) to a string by invoking the appropriate
180 /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
181 /// proceeds to call all the registered appenders in this logger
182 /// and also higher in the hierarchy depending on the value of
183 /// the additivity flag.
184 /// </para>
185 /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
186 /// to this method will print the name of the <see cref="Exception"/>
187 /// but no stack trace. To print a stack trace use the
188 /// <see cref="Debug(object,Exception)"/> form instead.
189 /// </para>
190 /// </remarks>
191 /// <seealso cref="Debug(object,Exception)"/>
192 /// <seealso cref="IsDebugEnabled"/>
193 public static void Debug(object message) {
194 facade.Debug(message);
197 /// <summary>
198 /// Log a message object with the <see cref="Level.Debug"/> level including
199 /// the stack trace of the <see cref="Exception"/> passed
200 /// as a parameter.
201 /// </summary>
202 /// <param name="message">The message object to log.</param>
203 /// <param name="exception">The exception to log, including its stack trace.</param>
204 /// <remarks>
205 /// <para>
206 /// See the <see cref="Debug(object)"/> form for more detailed information.
207 /// </para>
208 /// </remarks>
209 /// <seealso cref="Debug(object)"/>
210 /// <seealso cref="IsDebugEnabled"/>
211 public static void Debug(object message, Exception exception) {
212 facade.Debug(message, exception);
215 /// <overloads>Log a formatted string with the <see cref="Level.Debug"/> level.</overloads>
216 /// <summary>
217 /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
218 /// </summary>
219 /// <param name="format">A String containing zero or more format items</param>
220 /// <param name="args">An Object array containing zero or more objects to format</param>
221 /// <remarks>
222 /// <para>
223 /// The message is formatted using the <c>String.Format</c> method. See
224 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
225 /// of the formatting.
226 /// </para>
227 /// <para>
228 /// This method does not take an <see cref="Exception"/> object to include in the
229 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
230 /// methods instead.
231 /// </para>
232 /// </remarks>
233 /// <seealso cref="Debug(object)"/>
234 /// <seealso cref="IsDebugEnabled"/>
235 public static void DebugFormat(string format, params object[] args) {
236 facade.DebugFormat(CultureInfo.InvariantCulture, format, args);
239 /// <summary>
240 /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
241 /// </summary>
242 /// <param name="format">A String containing zero or more format items</param>
243 /// <param name="arg0">An Object to format</param>
244 /// <remarks>
245 /// <para>
246 /// The message is formatted using the <c>String.Format</c> method. See
247 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
248 /// of the formatting.
249 /// </para>
250 /// <para>
251 /// This method does not take an <see cref="Exception"/> object to include in the
252 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
253 /// methods instead.
254 /// </para>
255 /// </remarks>
256 /// <seealso cref="Debug(object)"/>
257 /// <seealso cref="IsDebugEnabled"/>
258 public static void DebugFormat(string format, object arg0) {
259 facade.DebugFormat(format, arg0);
262 /// <summary>
263 /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
264 /// </summary>
265 /// <param name="format">A String containing zero or more format items</param>
266 /// <param name="arg0">An Object to format</param>
267 /// <param name="arg1">An Object to format</param>
268 /// <remarks>
269 /// <para>
270 /// The message is formatted using the <c>String.Format</c> method. See
271 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
272 /// of the formatting.
273 /// </para>
274 /// <para>
275 /// This method does not take an <see cref="Exception"/> object to include in the
276 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
277 /// methods instead.
278 /// </para>
279 /// </remarks>
280 /// <seealso cref="Debug(object)"/>
281 /// <seealso cref="IsDebugEnabled"/>
282 public static void DebugFormat(string format, object arg0, object arg1) {
283 facade.DebugFormat(format, arg0, arg1);
286 /// <summary>
287 /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
288 /// </summary>
289 /// <param name="format">A String containing zero or more format items</param>
290 /// <param name="arg0">An Object to format</param>
291 /// <param name="arg1">An Object to format</param>
292 /// <param name="arg2">An Object to format</param>
293 /// <remarks>
294 /// <para>
295 /// The message is formatted using the <c>String.Format</c> method. See
296 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
297 /// of the formatting.
298 /// </para>
299 /// <para>
300 /// This method does not take an <see cref="Exception"/> object to include in the
301 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/>
302 /// methods instead.
303 /// </para>
304 /// </remarks>
305 /// <seealso cref="Debug(object)"/>
306 /// <seealso cref="IsDebugEnabled"/>
307 public static void DebugFormat(string format, object arg0, object arg1, object arg2) {
308 facade.DebugFormat(format, arg0, arg1, arg2);
312 public static void DebugFormat(IFormatProvider provider, string format, params object[] args) {
313 facade.DebugFormat(provider, format, args);
317 /// <overloads>Log a message object with the <see cref="Level.Info"/> level.</overloads>
318 /// <summary>
319 /// Logs a message object with the <see cref="Level.Info"/> level.
320 /// </summary>
321 /// <remarks>
322 /// <para>
323 /// This method first checks if this logger is <c>INFO</c>
324 /// enabled by comparing the level of this logger with the
325 /// <see cref="Level.Info"/> level. If this logger is
326 /// <c>INFO</c> enabled, then it converts the message object
327 /// (passed as parameter) to a string by invoking the appropriate
328 /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
329 /// proceeds to call all the registered appenders in this logger
330 /// and also higher in the hierarchy depending on the value of the
331 /// additivity flag.
332 /// </para>
333 /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
334 /// to this method will print the name of the <see cref="Exception"/>
335 /// but no stack trace. To print a stack trace use the
336 /// <see cref="Info(object,Exception)"/> form instead.
337 /// </para>
338 /// </remarks>
339 /// <param name="message">The message object to log.</param>
340 /// <seealso cref="Info(object,Exception)"/>
341 /// <seealso cref="IsInfoEnabled"/>
342 public static void Info(object message) {
343 facade.Info(message);
346 /// <summary>
347 /// Logs a message object with the <c>INFO</c> level including
348 /// the stack trace of the <see cref="Exception"/> passed
349 /// as a parameter.
350 /// </summary>
351 /// <param name="message">The message object to log.</param>
352 /// <param name="exception">The exception to log, including its stack trace.</param>
353 /// <remarks>
354 /// <para>
355 /// See the <see cref="Info(object)"/> form for more detailed information.
356 /// </para>
357 /// </remarks>
358 /// <seealso cref="Info(object)"/>
359 /// <seealso cref="IsInfoEnabled"/>
360 public static void Info(object message, Exception exception) {
361 facade.Info(message, exception);
364 /// <overloads>Log a formatted message string with the <see cref="Level.Info"/> level.</overloads>
365 /// <summary>
366 /// Logs a formatted message string with the <see cref="Level.Info"/> level.
367 /// </summary>
368 /// <param name="format">A String containing zero or more format items</param>
369 /// <param name="args">An Object array containing zero or more objects to format</param>
370 /// <remarks>
371 /// <para>
372 /// The message is formatted using the <c>String.Format</c> method. See
373 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
374 /// of the formatting.
375 /// </para>
376 /// <para>
377 /// This method does not take an <see cref="Exception"/> object to include in the
378 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/>
379 /// methods instead.
380 /// </para>
381 /// </remarks>
382 /// <seealso cref="Info(object,Exception)"/>
383 /// <seealso cref="IsInfoEnabled"/>
384 public static void InfoFormat(string format, params object[] args) {
385 facade.InfoFormat(CultureInfo.InvariantCulture, format, args);
388 /// <summary>
389 /// Logs a formatted message string with the <see cref="Level.Info"/> level.
390 /// </summary>
391 /// <param name="format">A String containing zero or more format items</param>
392 /// <param name="arg0">An Object to format</param>
393 /// <remarks>
394 /// <para>
395 /// The message is formatted using the <c>String.Format</c> method. See
396 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
397 /// of the formatting.
398 /// </para>
399 /// <para>
400 /// This method does not take an <see cref="Exception"/> object to include in the
401 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
402 /// methods instead.
403 /// </para>
404 /// </remarks>
405 /// <seealso cref="Info(object)"/>
406 /// <seealso cref="IsInfoEnabled"/>
407 public static void InfoFormat(string format, object arg0) {
408 facade.InfoFormat(format, arg0);
411 /// <summary>
412 /// Logs a formatted message string with the <see cref="Level.Info"/> level.
413 /// </summary>
414 /// <param name="format">A String containing zero or more format items</param>
415 /// <param name="arg0">An Object to format</param>
416 /// <param name="arg1">An Object to format</param>
417 /// <remarks>
418 /// <para>
419 /// The message is formatted using the <c>String.Format</c> method. See
420 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
421 /// of the formatting.
422 /// </para>
423 /// <para>
424 /// This method does not take an <see cref="Exception"/> object to include in the
425 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
426 /// methods instead.
427 /// </para>
428 /// </remarks>
429 /// <seealso cref="Info(object)"/>
430 /// <seealso cref="IsInfoEnabled"/>
431 public static void InfoFormat(string format, object arg0, object arg1) {
432 facade.InfoFormat(format, arg0, arg1);
435 /// <summary>
436 /// Logs a formatted message string with the <see cref="Level.Info"/> level.
437 /// </summary>
438 /// <param name="format">A String containing zero or more format items</param>
439 /// <param name="arg0">An Object to format</param>
440 /// <param name="arg1">An Object to format</param>
441 /// <param name="arg2">An Object to format</param>
442 /// <remarks>
443 /// <para>
444 /// The message is formatted using the <c>String.Format</c> method. See
445 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
446 /// of the formatting.
447 /// </para>
448 /// <para>
449 /// This method does not take an <see cref="Exception"/> object to include in the
450 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/>
451 /// methods instead.
452 /// </para>
453 /// </remarks>
454 /// <seealso cref="Info(object)"/>
455 /// <seealso cref="IsInfoEnabled"/>
456 public static void InfoFormat(string format, object arg0, object arg1, object arg2) {
457 facade.InfoFormat(format, arg0, arg1, arg2);
461 public static void InfoFormat(IFormatProvider provider, string format, params object[] args) {
462 facade.InfoFormat(provider, format, args);
466 /// <overloads>Log a message object with the <see cref="Level.Warn"/> level.</overloads>
467 /// <summary>
468 /// Log a message object with the <see cref="Level.Warn"/> level.
469 /// </summary>
470 /// <remarks>
471 /// <para>
472 /// This method first checks if this logger is <c>WARN</c>
473 /// enabled by comparing the level of this logger with the
474 /// <see cref="Level.Warn"/> level. If this logger is
475 /// <c>WARN</c> enabled, then it converts the message object
476 /// (passed as parameter) to a string by invoking the appropriate
477 /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
478 /// proceeds to call all the registered appenders in this logger
479 /// and also higher in the hierarchy depending on the value of the
480 /// additivity flag.
481 /// </para>
482 /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
483 /// to this method will print the name of the <see cref="Exception"/>
484 /// but no stack trace. To print a stack trace use the
485 /// <see cref="Warn(object,Exception)"/> form instead.
486 /// </para>
487 /// </remarks>
488 /// <param name="message">The message object to log.</param>
489 /// <seealso cref="Warn(object,Exception)"/>
490 /// <seealso cref="IsWarnEnabled"/>
491 public static void Warn(object message) {
492 facade.Warn(message);
495 /// <summary>
496 /// Log a message object with the <see cref="Level.Warn"/> level including
497 /// the stack trace of the <see cref="Exception"/> passed
498 /// as a parameter.
499 /// </summary>
500 /// <param name="message">The message object to log.</param>
501 /// <param name="exception">The exception to log, including its stack trace.</param>
502 /// <remarks>
503 /// <para>
504 /// See the <see cref="Warn(object)"/> form for more detailed information.
505 /// </para>
506 /// </remarks>
507 /// <seealso cref="Warn(object)"/>
508 /// <seealso cref="IsWarnEnabled"/>
509 public static void Warn(object message, Exception exception) {
510 facade.Warn(message, exception);
513 /// <overloads>Log a formatted message string with the <see cref="Level.Warn"/> level.</overloads>
514 /// <summary>
515 /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
516 /// </summary>
517 /// <param name="format">A String containing zero or more format items</param>
518 /// <param name="args">An Object array containing zero or more objects to format</param>
519 /// <remarks>
520 /// <para>
521 /// The message is formatted using the <c>String.Format</c> method. See
522 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
523 /// of the formatting.
524 /// </para>
525 /// <para>
526 /// This method does not take an <see cref="Exception"/> object to include in the
527 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/>
528 /// methods instead.
529 /// </para>
530 /// </remarks>
531 /// <seealso cref="Warn(object,Exception)"/>
532 /// <seealso cref="IsWarnEnabled"/>
533 public static void WarnFormat(string format, params object[] args) {
534 facade.WarnFormat(CultureInfo.InvariantCulture, format, args);
537 /// <summary>
538 /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
539 /// </summary>
540 /// <param name="format">A String containing zero or more format items</param>
541 /// <param name="arg0">An Object to format</param>
542 /// <remarks>
543 /// <para>
544 /// The message is formatted using the <c>String.Format</c> method. See
545 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
546 /// of the formatting.
547 /// </para>
548 /// <para>
549 /// This method does not take an <see cref="Exception"/> object to include in the
550 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
551 /// methods instead.
552 /// </para>
553 /// </remarks>
554 /// <seealso cref="Warn(object)"/>
555 /// <seealso cref="IsWarnEnabled"/>
556 public static void WarnFormat(string format, object arg0) {
557 facade.WarnFormat(format, arg0);
560 /// <summary>
561 /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
562 /// </summary>
563 /// <param name="format">A String containing zero or more format items</param>
564 /// <param name="arg0">An Object to format</param>
565 /// <param name="arg1">An Object to format</param>
566 /// <remarks>
567 /// <para>
568 /// The message is formatted using the <c>String.Format</c> method. See
569 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
570 /// of the formatting.
571 /// </para>
572 /// <para>
573 /// This method does not take an <see cref="Exception"/> object to include in the
574 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
575 /// methods instead.
576 /// </para>
577 /// </remarks>
578 /// <seealso cref="Warn(object)"/>
579 /// <seealso cref="IsWarnEnabled"/>
580 public static void WarnFormat(string format, object arg0, object arg1) {
581 facade.WarnFormat(format, arg0, arg1);
584 /// <summary>
585 /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
586 /// </summary>
587 /// <param name="format">A String containing zero or more format items</param>
588 /// <param name="arg0">An Object to format</param>
589 /// <param name="arg1">An Object to format</param>
590 /// <param name="arg2">An Object to format</param>
591 /// <remarks>
592 /// <para>
593 /// The message is formatted using the <c>String.Format</c> method. See
594 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
595 /// of the formatting.
596 /// </para>
597 /// <para>
598 /// This method does not take an <see cref="Exception"/> object to include in the
599 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/>
600 /// methods instead.
601 /// </para>
602 /// </remarks>
603 /// <seealso cref="Warn(object)"/>
604 /// <seealso cref="IsWarnEnabled"/>
605 public static void WarnFormat(string format, object arg0, object arg1, object arg2) {
606 facade.WarnFormat(format, arg0, arg1, arg2);
610 public static void WarnFormat(IFormatProvider provider, string format, params object[] args) {
611 facade.WarnFormat(provider, format, args);
615 /// <overloads>Log a message object with the <see cref="Level.Error"/> level.</overloads>
616 /// <summary>
617 /// Logs a message object with the <see cref="Level.Error"/> level.
618 /// </summary>
619 /// <param name="message">The message object to log.</param>
620 /// <remarks>
621 /// <para>
622 /// This method first checks if this logger is <c>ERROR</c>
623 /// enabled by comparing the level of this logger with the
624 /// <see cref="Level.Error"/> level. If this logger is
625 /// <c>ERROR</c> enabled, then it converts the message object
626 /// (passed as parameter) to a string by invoking the appropriate
627 /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
628 /// proceeds to call all the registered appenders in this logger
629 /// and also higher in the hierarchy depending on the value of the
630 /// additivity flag.
631 /// </para>
632 /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
633 /// to this method will print the name of the <see cref="Exception"/>
634 /// but no stack trace. To print a stack trace use the
635 /// <see cref="Error(object,Exception)"/> form instead.
636 /// </para>
637 /// </remarks>
638 /// <seealso cref="Error(object,Exception)"/>
639 /// <seealso cref="IsErrorEnabled"/>
640 public static void Error(object message) {
641 facade.Error(message);
644 /// <summary>
645 /// Log a message object with the <see cref="Level.Error"/> level including
646 /// the stack trace of the <see cref="Exception"/> passed
647 /// as a parameter.
648 /// </summary>
649 /// <param name="message">The message object to log.</param>
650 /// <param name="exception">The exception to log, including its stack trace.</param>
651 /// <remarks>
652 /// <para>
653 /// See the <see cref="Error(object)"/> form for more detailed information.
654 /// </para>
655 /// </remarks>
656 /// <seealso cref="Error(object)"/>
657 /// <seealso cref="IsErrorEnabled"/>
658 public static void Error(object message, Exception exception) {
659 facade.Error(message, exception);
662 /// <overloads>Log a formatted message string with the <see cref="Level.Error"/> level.</overloads>
663 /// <summary>
664 /// Logs a formatted message string with the <see cref="Level.Error"/> level.
665 /// </summary>
666 /// <param name="format">A String containing zero or more format items</param>
667 /// <param name="args">An Object array containing zero or more objects to format</param>
668 /// <remarks>
669 /// <para>
670 /// The message is formatted using the <c>String.Format</c> method. See
671 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
672 /// of the formatting.
673 /// </para>
674 /// <para>
675 /// This method does not take an <see cref="Exception"/> object to include in the
676 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/>
677 /// methods instead.
678 /// </para>
679 /// </remarks>
680 /// <seealso cref="Error(object,Exception)"/>
681 /// <seealso cref="IsErrorEnabled"/>
682 public static void ErrorFormat(string format, params object[] args) {
683 facade.ErrorFormat(CultureInfo.InvariantCulture, format, args);
686 /// <summary>
687 /// Logs a formatted message string with the <see cref="Level.Error"/> level.
688 /// </summary>
689 /// <param name="format">A String containing zero or more format items</param>
690 /// <param name="arg0">An Object to format</param>
691 /// <remarks>
692 /// <para>
693 /// The message is formatted using the <c>String.Format</c> method. See
694 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
695 /// of the formatting.
696 /// </para>
697 /// <para>
698 /// This method does not take an <see cref="Exception"/> object to include in the
699 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
700 /// methods instead.
701 /// </para>
702 /// </remarks>
703 /// <seealso cref="Error(object)"/>
704 /// <seealso cref="IsErrorEnabled"/>
705 public static void ErrorFormat(string format, object arg0) {
706 facade.ErrorFormat(format, arg0);
709 /// <summary>
710 /// Logs a formatted message string with the <see cref="Level.Error"/> level.
711 /// </summary>
712 /// <param name="format">A String containing zero or more format items</param>
713 /// <param name="arg0">An Object to format</param>
714 /// <param name="arg1">An Object to format</param>
715 /// <remarks>
716 /// <para>
717 /// The message is formatted using the <c>String.Format</c> method. See
718 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
719 /// of the formatting.
720 /// </para>
721 /// <para>
722 /// This method does not take an <see cref="Exception"/> object to include in the
723 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
724 /// methods instead.
725 /// </para>
726 /// </remarks>
727 /// <seealso cref="Error(object)"/>
728 /// <seealso cref="IsErrorEnabled"/>
729 public static void ErrorFormat(string format, object arg0, object arg1) {
730 facade.ErrorFormat(format, arg0, arg1);
733 /// <summary>
734 /// Logs a formatted message string with the <see cref="Level.Error"/> level.
735 /// </summary>
736 /// <param name="format">A String containing zero or more format items</param>
737 /// <param name="arg0">An Object to format</param>
738 /// <param name="arg1">An Object to format</param>
739 /// <param name="arg2">An Object to format</param>
740 /// <remarks>
741 /// <para>
742 /// The message is formatted using the <c>String.Format</c> method. See
743 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
744 /// of the formatting.
745 /// </para>
746 /// <para>
747 /// This method does not take an <see cref="Exception"/> object to include in the
748 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/>
749 /// methods instead.
750 /// </para>
751 /// </remarks>
752 /// <seealso cref="Error(object)"/>
753 /// <seealso cref="IsErrorEnabled"/>
754 public static void ErrorFormat(string format, object arg0, object arg1, object arg2) {
755 facade.ErrorFormat(format, arg0, arg1, arg2);
759 public static void ErrorFormat(IFormatProvider provider, string format, params object[] args) {
760 facade.ErrorFormat(provider, format, args);
764 /// <overloads>Log a message object with the <see cref="Level.Fatal"/> level.</overloads>
765 /// <summary>
766 /// Log a message object with the <see cref="Level.Fatal"/> level.
767 /// </summary>
768 /// <remarks>
769 /// <para>
770 /// This method first checks if this logger is <c>FATAL</c>
771 /// enabled by comparing the level of this logger with the
772 /// <see cref="Level.Fatal"/> level. If this logger is
773 /// <c>FATAL</c> enabled, then it converts the message object
774 /// (passed as parameter) to a string by invoking the appropriate
775 /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
776 /// proceeds to call all the registered appenders in this logger
777 /// and also higher in the hierarchy depending on the value of the
778 /// additivity flag.
779 /// </para>
780 /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
781 /// to this method will print the name of the <see cref="Exception"/>
782 /// but no stack trace. To print a stack trace use the
783 /// <see cref="Fatal(object,Exception)"/> form instead.
784 /// </para>
785 /// </remarks>
786 /// <param name="message">The message object to log.</param>
787 /// <seealso cref="Fatal(object,Exception)"/>
788 /// <seealso cref="IsFatalEnabled"/>
789 public static void Fatal(object message) {
790 facade.Fatal(message);
793 /// <summary>
794 /// Log a message object with the <see cref="Level.Fatal"/> level including
795 /// the stack trace of the <see cref="Exception"/> passed
796 /// as a parameter.
797 /// </summary>
798 /// <param name="message">The message object to log.</param>
799 /// <param name="exception">The exception to log, including its stack trace.</param>
800 /// <remarks>
801 /// <para>
802 /// See the <see cref="Fatal(object)"/> form for more detailed information.
803 /// </para>
804 /// </remarks>
805 /// <seealso cref="Fatal(object)"/>
806 /// <seealso cref="IsFatalEnabled"/>
807 public static void Fatal(object message, Exception exception) {
808 facade.Fatal(message, exception);
811 /// <overloads>Log a formatted message string with the <see cref="Level.Fatal"/> level.</overloads>
812 /// <summary>
813 /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
814 /// </summary>
815 /// <param name="format">A String containing zero or more format items</param>
816 /// <param name="args">An Object array containing zero or more objects to format</param>
817 /// <remarks>
818 /// <para>
819 /// The message is formatted using the <c>String.Format</c> method. See
820 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
821 /// of the formatting.
822 /// </para>
823 /// <para>
824 /// This method does not take an <see cref="Exception"/> object to include in the
825 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/>
826 /// methods instead.
827 /// </para>
828 /// </remarks>
829 /// <seealso cref="Fatal(object,Exception)"/>
830 /// <seealso cref="IsFatalEnabled"/>
831 public static void FatalFormat(string format, params object[] args) {
832 facade.FatalFormat(CultureInfo.InvariantCulture, format, args);
835 /// <summary>
836 /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
837 /// </summary>
838 /// <param name="format">A String containing zero or more format items</param>
839 /// <param name="arg0">An Object to format</param>
840 /// <remarks>
841 /// <para>
842 /// The message is formatted using the <c>String.Format</c> method. See
843 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
844 /// of the formatting.
845 /// </para>
846 /// <para>
847 /// This method does not take an <see cref="Exception"/> object to include in the
848 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
849 /// methods instead.
850 /// </para>
851 /// </remarks>
852 /// <seealso cref="Fatal(object)"/>
853 /// <seealso cref="IsFatalEnabled"/>
854 public static void FatalFormat(string format, object arg0) {
855 facade.FatalFormat(format, arg0);
858 /// <summary>
859 /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
860 /// </summary>
861 /// <param name="format">A String containing zero or more format items</param>
862 /// <param name="arg0">An Object to format</param>
863 /// <param name="arg1">An Object to format</param>
864 /// <remarks>
865 /// <para>
866 /// The message is formatted using the <c>String.Format</c> method. See
867 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
868 /// of the formatting.
869 /// </para>
870 /// <para>
871 /// This method does not take an <see cref="Exception"/> object to include in the
872 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
873 /// methods instead.
874 /// </para>
875 /// </remarks>
876 /// <seealso cref="Fatal(object)"/>
877 /// <seealso cref="IsFatalEnabled"/>
878 public static void FatalFormat(string format, object arg0, object arg1) {
879 facade.FatalFormat(format, arg0, arg1);
882 /// <summary>
883 /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
884 /// </summary>
885 /// <param name="format">A String containing zero or more format items</param>
886 /// <param name="arg0">An Object to format</param>
887 /// <param name="arg1">An Object to format</param>
888 /// <param name="arg2">An Object to format</param>
889 /// <remarks>
890 /// <para>
891 /// The message is formatted using the <c>String.Format</c> method. See
892 /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
893 /// of the formatting.
894 /// </para>
895 /// <para>
896 /// This method does not take an <see cref="Exception"/> object to include in the
897 /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/>
898 /// methods instead.
899 /// </para>
900 /// </remarks>
901 /// <seealso cref="Fatal(object)"/>
902 /// <seealso cref="IsFatalEnabled"/>
903 public static void FatalFormat(string format, object arg0, object arg1, object arg2) {
904 facade.FatalFormat(format, arg0, arg1, arg2);
908 public static void FatalFormat(IFormatProvider provider, string format, params object[] args) {
909 facade.FatalFormat(provider, format, args);
913 #endregion
915 /// <summary>
916 /// Discovers the presence of Log4net.dll and other logging mechanisms
917 /// and returns the best available logger.
918 /// </summary>
919 /// <returns>The <see cref="ILog"/> instance of the logger to use.</returns>
920 private static ILog InitializeFacade() {
921 ILog result = Log4NetLogger.Initialize() ?? TraceLogger.Initialize() ?? NoOpLogger.Initialize();
922 result.Info(Util.LibraryVersion);
923 return result;