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