ILogExtensions.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  1. #region Apache License
  2. //
  3. // Licensed to the Apache Software Foundation (ASF) under one or more
  4. // contributor license agreements. See the NOTICE file distributed with
  5. // this work for additional information regarding copyright ownership.
  6. // The ASF licenses this file to you under the Apache License, Version 2.0
  7. // (the "License"); you may not use this file except in compliance with
  8. // the License. You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //
  18. #endregion
  19. #if NET_3_5 || NET_4_0 || MONO_3_5 || MONO_4_0 || NETSTANDARD1_3
  20. using System;
  21. using log4net.Core;
  22. namespace log4net.Util
  23. {
  24. /// <summary>
  25. /// The static class ILogExtensions contains a set of widely used
  26. /// methods that ease the interaction with the ILog interface implementations.
  27. /// </summary>
  28. /// <remarks>
  29. /// <para>
  30. /// This class contains methods for logging at different levels and checks the
  31. /// properties for determining if those logging levels are enabled in the current
  32. /// configuration.
  33. /// </para>
  34. /// </remarks>
  35. /// <example>Simple example of logging messages
  36. /// <code lang="C#">
  37. /// using log4net.Util;
  38. ///
  39. /// ILog log = LogManager.GetLogger("application-log");
  40. ///
  41. /// log.InfoExt("Application Start");
  42. /// log.DebugExt("This is a debug message");
  43. /// </code>
  44. /// </example>
  45. public static class ILogExtensions
  46. {
  47. #region Private Static Fields
  48. /// <summary>
  49. /// The fully qualified type of the Logger class.
  50. /// </summary>
  51. private readonly static Type declaringType = typeof(ILogExtensions);
  52. #endregion //Private Static Fields
  53. #region debug extensions
  54. #region debug extensions that uses log message lambda expression
  55. /// <summary>
  56. /// Log a message object with the <see cref="Level.Debug"/> level.
  57. /// </summary>
  58. /// <param name="logger">The logger on which the message is logged.</param>
  59. /// <param name="callback">The lambda expression that gets the object to log.</param>
  60. /// <remarks>
  61. /// <para>
  62. /// This method first checks if this logger is <c>INFO</c>
  63. /// enabled by reading the value <seealso cref="ILog.IsDebugEnabled"/> property.
  64. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  65. /// implementation. If this logger is <c>INFO</c> enabled, then it converts
  66. /// the message object (retrieved by invocation of the provided callback) to a
  67. /// string by invoking the appropriate <see cref="log4net.ObjectRenderer.IObjectRenderer"/>.
  68. /// It then proceeds to call all the registered appenders in this logger
  69. /// and also higher in the hierarchy depending on the value of
  70. /// the additivity flag.
  71. /// </para>
  72. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  73. /// to this method will print the name of the <see cref="Exception"/>
  74. /// but no stack trace. To print a stack trace use the
  75. /// <see cref="DebugExt(ILog,Func{object},Exception)"/> form instead.
  76. /// </para>
  77. /// </remarks>
  78. /// <seealso cref="ILog.Debug(object)"/>
  79. /// <seealso cref="ILog.IsDebugEnabled"/>
  80. public static void DebugExt(this ILog logger, Func<object> callback)
  81. {
  82. try
  83. {
  84. if (!logger.IsDebugEnabled)
  85. return;
  86. logger.Debug(callback());
  87. }
  88. catch (Exception ex)
  89. {
  90. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  91. }
  92. }
  93. /// <summary>
  94. /// Log a message object with the <see cref="Level.Debug"/> level including
  95. /// the stack trace of the <see cref="Exception"/> passed
  96. /// as a parameter.
  97. /// </summary>
  98. /// <param name="logger">The logger on which the message is logged.</param>
  99. /// <param name="callback">The lambda expression that gets the object to log.</param>
  100. /// <param name="exception">The exception to log, including its stack trace.</param>
  101. /// <remarks>
  102. /// <para>
  103. /// See the <see cref="DebugExt(ILog, object)"/> form for more detailed information.
  104. /// </para>
  105. /// </remarks>
  106. /// <seealso cref="ILog.Debug(object)"/>
  107. /// <seealso cref="ILog.IsDebugEnabled"/>
  108. public static void DebugExt(this ILog logger, Func<object> callback, Exception exception)
  109. {
  110. try
  111. {
  112. if (!logger.IsDebugEnabled)
  113. return;
  114. logger.Debug(callback(), exception);
  115. }
  116. catch (Exception ex)
  117. {
  118. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  119. }
  120. }
  121. #endregion
  122. #region debug extension that use the formatter
  123. /// <overloads>Log a message object with the <see cref="Level.Debug"/> level.</overloads> //TODO
  124. /// <summary>
  125. /// Log a message object with the <see cref="Level.Debug"/> level.
  126. /// </summary>
  127. /// <param name="logger">The logger on which the message is logged.</param>
  128. /// <param name="message">The message object to log.</param>
  129. /// <remarks>
  130. /// <para>
  131. /// This method first checks if this logger is <c>INFO</c>
  132. /// enabled by reading the value <seealso cref="ILog.IsDebugEnabled"/> property.
  133. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  134. /// implementation. If this logger is <c>INFO</c> enabled, then it converts
  135. /// the message object (passed as parameter) to a string by invoking the appropriate
  136. /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
  137. /// proceeds to call all the registered appenders in this logger
  138. /// and also higher in the hierarchy depending on the value of
  139. /// the additivity flag.
  140. /// </para>
  141. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  142. /// to this method will print the name of the <see cref="Exception"/>
  143. /// but no stack trace. To print a stack trace use the
  144. /// <see cref="DebugExt(ILog,object,Exception)"/> form instead.
  145. /// </para>
  146. /// </remarks>
  147. /// <seealso cref="ILog.Debug(object)"/>
  148. /// <seealso cref="ILog.IsDebugEnabled"/>
  149. public static void DebugExt(this ILog logger, object message)
  150. {
  151. try
  152. {
  153. if (!logger.IsDebugEnabled)
  154. return;
  155. logger.Debug(message);
  156. }
  157. catch (Exception ex)
  158. {
  159. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  160. }
  161. }
  162. /// <summary>
  163. /// Log a message object with the <see cref="Level.Debug"/> level including
  164. /// the stack trace of the <see cref="Exception"/> passed
  165. /// as a parameter.
  166. /// </summary>
  167. /// <param name="logger">The logger on which the message is logged.</param>
  168. /// <param name="message">The message object to log.</param>
  169. /// <param name="exception">The exception to log, including its stack trace.</param>
  170. /// <remarks>
  171. /// <para>
  172. /// See the <see cref="DebugExt(ILog, object)"/> form for more detailed information.
  173. /// </para>
  174. /// </remarks>
  175. /// <seealso cref="ILog.Debug(object)"/>
  176. /// <seealso cref="ILog.IsDebugEnabled"/>
  177. public static void DebugExt(this ILog logger, object message, Exception exception)
  178. {
  179. try
  180. {
  181. if (!logger.IsDebugEnabled)
  182. return;
  183. logger.Debug(message, exception);
  184. }
  185. catch (Exception ex)
  186. {
  187. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  188. }
  189. }
  190. #endregion
  191. #region debug extension that use string format
  192. /// <summary>
  193. /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
  194. /// </summary>
  195. /// <param name="logger">The logger on which the message is logged.</param>
  196. /// <param name="format">A String containing zero or more format items</param>
  197. /// <param name="arg0">An Object to format</param>
  198. /// <remarks>
  199. /// <para>
  200. /// The message is formatted using the <c>String.Format</c> method. See
  201. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  202. /// of the formatting.
  203. /// </para>
  204. /// <para>
  205. /// This method does not take an <see cref="Exception"/> object to include in the
  206. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="DebugExt(ILog,object,Exception)"/>
  207. /// methods instead.
  208. /// </para>
  209. /// </remarks>
  210. /// <seealso cref="ILog.Debug(object)"/>
  211. /// <seealso cref="ILog.IsDebugEnabled"/>
  212. public static void DebugFormatExt(this ILog logger, string format, object arg0)
  213. {
  214. try
  215. {
  216. if (!logger.IsDebugEnabled)
  217. return;
  218. logger.DebugFormat(format, arg0);
  219. }
  220. catch (Exception ex)
  221. {
  222. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  223. }
  224. }
  225. /// <summary>
  226. /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
  227. /// </summary>
  228. /// <param name="logger">The logger on which the message is logged.</param>
  229. /// <param name="format">A String containing zero or more format items</param>
  230. /// <param name="args">An Object array containing zero or more objects to format</param>
  231. /// <remarks>
  232. /// <para>
  233. /// The message is formatted using the <c>String.Format</c> method. See
  234. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  235. /// of the formatting.
  236. /// </para>
  237. /// <para>
  238. /// This method does not take an <see cref="Exception"/> object to include in the
  239. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="DebugExt(ILog,object,Exception)"/>
  240. /// methods instead.
  241. /// </para>
  242. /// </remarks>
  243. /// <seealso cref="ILog.Debug(object)"/>
  244. /// <seealso cref="ILog.IsDebugEnabled"/>
  245. public static void DebugFormatExt(this ILog logger, string format, params object[] args)
  246. {
  247. try
  248. {
  249. if (!logger.IsDebugEnabled)
  250. return;
  251. logger.DebugFormat(format, args);
  252. }
  253. catch (Exception ex)
  254. {
  255. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  256. }
  257. }
  258. /// <summary>
  259. /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
  260. /// </summary>
  261. /// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
  262. /// <param name="logger">The logger on which the message is logged.</param>
  263. /// <param name="format">A String containing zero or more format items</param>
  264. /// <param name="args">An Object array containing zero or more objects to format</param>
  265. /// <remarks>
  266. /// <para>
  267. /// The message is formatted using the <c>String.Format</c> method. See
  268. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  269. /// of the formatting.
  270. /// </para>
  271. /// <para>
  272. /// This method does not take an <see cref="Exception"/> object to include in the
  273. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="DebugExt(ILog,object,Exception)"/>
  274. /// methods instead.
  275. /// </para>
  276. /// </remarks>
  277. /// <seealso cref="ILog.Debug(object)"/>
  278. /// <seealso cref="ILog.IsDebugEnabled"/>
  279. public static void DebugFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args)
  280. {
  281. try
  282. {
  283. if (!logger.IsDebugEnabled)
  284. return;
  285. logger.DebugFormat(provider, format, args);
  286. }
  287. catch (Exception ex)
  288. {
  289. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  290. }
  291. }
  292. /// <summary>
  293. /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
  294. /// </summary>
  295. /// <param name="logger">The logger on which the message is logged.</param>
  296. /// <param name="format">A String containing zero or more format items</param>
  297. /// <param name="arg0">An Object to format</param>
  298. /// <param name="arg1">An Object to format</param>
  299. /// <remarks>
  300. /// <para>
  301. /// The message is formatted using the <c>String.Format</c> method. See
  302. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  303. /// of the formatting.
  304. /// </para>
  305. /// <para>
  306. /// This method does not take an <see cref="Exception"/> object to include in the
  307. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="DebugExt(ILog,object,Exception)"/>
  308. /// methods instead.
  309. /// </para>
  310. /// </remarks>
  311. /// <seealso cref="ILog.Debug(object)"/>
  312. /// <seealso cref="ILog.IsDebugEnabled"/>
  313. public static void DebugFormatExt(this ILog logger, string format, object arg0, object arg1)
  314. {
  315. try
  316. {
  317. if (!logger.IsDebugEnabled)
  318. return;
  319. logger.DebugFormat(format, arg0, arg1);
  320. }
  321. catch (Exception ex)
  322. {
  323. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  324. }
  325. }
  326. /// <summary>
  327. /// Logs a formatted message string with the <see cref="Level.Debug"/> level.
  328. /// </summary>
  329. /// <param name="logger">The logger on which the message is logged.</param>
  330. /// <param name="format">A String containing zero or more format items</param>
  331. /// <param name="arg0">An Object to format</param>
  332. /// <param name="arg1">An Object to format</param>
  333. /// <param name="arg2">An Object to format</param>
  334. /// <remarks>
  335. /// <para>
  336. /// The message is formatted using the <c>String.Format</c> method. See
  337. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  338. /// of the formatting.
  339. /// </para>
  340. /// <para>
  341. /// This method does not take an <see cref="Exception"/> object to include in the
  342. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="DebugExt(ILog,object,Exception)"/>
  343. /// methods instead.
  344. /// </para>
  345. /// </remarks>
  346. /// <seealso cref="ILog.Debug(object)"/>
  347. /// <seealso cref="ILog.IsDebugEnabled"/>
  348. public static void DebugFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2)
  349. {
  350. try
  351. {
  352. if (!logger.IsDebugEnabled)
  353. return;
  354. logger.DebugFormat(format, arg0, arg1, arg2);
  355. }
  356. catch (Exception ex)
  357. {
  358. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  359. }
  360. }
  361. #endregion
  362. #endregion
  363. #region info extensions
  364. #region info extensions that uses log message lambda expression
  365. /// <summary>
  366. /// Log a message object with the <see cref="Level.Info"/> level.
  367. /// </summary>
  368. /// <param name="logger">The logger on which the message is logged.</param>
  369. /// <param name="callback">The lambda expression that gets the object to log.</param>
  370. /// <remarks>
  371. /// <para>
  372. /// This method first checks if this logger is <c>INFO</c>
  373. /// enabled by reading the value <seealso cref="ILog.IsInfoEnabled"/> property.
  374. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  375. /// implementation. If this logger is <c>INFO</c> enabled, then it converts
  376. /// the message object (retrieved by invocation of the provided callback) to a
  377. /// string by invoking the appropriate <see cref="log4net.ObjectRenderer.IObjectRenderer"/>.
  378. /// It then proceeds to call all the registered appenders in this logger
  379. /// and also higher in the hierarchy depending on the value of
  380. /// the additivity flag.
  381. /// </para>
  382. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  383. /// to this method will print the name of the <see cref="Exception"/>
  384. /// but no stack trace. To print a stack trace use the
  385. /// <see cref="InfoExt(ILog,Func{object},Exception)"/> form instead.
  386. /// </para>
  387. /// </remarks>
  388. /// <seealso cref="ILog.Info(object)"/>
  389. /// <seealso cref="ILog.IsInfoEnabled"/>
  390. public static void InfoExt(this ILog logger, Func<object> callback)
  391. {
  392. try
  393. {
  394. if (!logger.IsInfoEnabled)
  395. return;
  396. logger.Info(callback());
  397. }
  398. catch (Exception ex)
  399. {
  400. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  401. }
  402. }
  403. /// <summary>
  404. /// Log a message object with the <see cref="Level.Info"/> level including
  405. /// the stack trace of the <see cref="Exception"/> passed
  406. /// as a parameter.
  407. /// </summary>
  408. /// <param name="logger">The logger on which the message is logged.</param>
  409. /// <param name="callback">The lambda expression that gets the object to log.</param>
  410. /// <param name="exception">The exception to log, including its stack trace.</param>
  411. /// <remarks>
  412. /// <para>
  413. /// See the <see cref="InfoExt(ILog, object)"/> form for more detailed information.
  414. /// </para>
  415. /// </remarks>
  416. /// <seealso cref="ILog.Info(object)"/>
  417. /// <seealso cref="ILog.IsInfoEnabled"/>
  418. public static void InfoExt(this ILog logger, Func<object> callback, Exception exception)
  419. {
  420. try
  421. {
  422. if (!logger.IsInfoEnabled)
  423. return;
  424. logger.Info(callback(), exception);
  425. }
  426. catch (Exception ex)
  427. {
  428. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  429. }
  430. }
  431. #endregion
  432. #region info extension that use the formatter
  433. /// <overloads>Log a message object with the <see cref="Level.Info"/> level.</overloads> //TODO
  434. /// <summary>
  435. /// Log a message object with the <see cref="Level.Info"/> level.
  436. /// </summary>
  437. /// <param name="logger">The logger on which the message is logged.</param>
  438. /// <param name="message">The message object to log.</param>
  439. /// <remarks>
  440. /// <para>
  441. /// This method first checks if this logger is <c>INFO</c>
  442. /// enabled by reading the value <seealso cref="ILog.IsInfoEnabled"/> property.
  443. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  444. /// implementation. If this logger is <c>INFO</c> enabled, then it converts
  445. /// the message object (passed as parameter) to a string by invoking the appropriate
  446. /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
  447. /// proceeds to call all the registered appenders in this logger
  448. /// and also higher in the hierarchy depending on the value of
  449. /// the additivity flag.
  450. /// </para>
  451. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  452. /// to this method will print the name of the <see cref="Exception"/>
  453. /// but no stack trace. To print a stack trace use the
  454. /// <see cref="InfoExt(ILog,object,Exception)"/> form instead.
  455. /// </para>
  456. /// </remarks>
  457. /// <seealso cref="ILog.Info(object)"/>
  458. /// <seealso cref="ILog.IsInfoEnabled"/>
  459. public static void InfoExt(this ILog logger, object message)
  460. {
  461. try
  462. {
  463. if (!logger.IsInfoEnabled)
  464. return;
  465. logger.Info(message);
  466. }
  467. catch (Exception ex)
  468. {
  469. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  470. }
  471. }
  472. /// <summary>
  473. /// Log a message object with the <see cref="Level.Info"/> level including
  474. /// the stack trace of the <see cref="Exception"/> passed
  475. /// as a parameter.
  476. /// </summary>
  477. /// <param name="logger">The logger on which the message is logged.</param>
  478. /// <param name="message">The message object to log.</param>
  479. /// <param name="exception">The exception to log, including its stack trace.</param>
  480. /// <remarks>
  481. /// <para>
  482. /// See the <see cref="InfoExt(ILog, object)"/> form for more detailed information.
  483. /// </para>
  484. /// </remarks>
  485. /// <seealso cref="ILog.Info(object)"/>
  486. /// <seealso cref="ILog.IsInfoEnabled"/>
  487. public static void InfoExt(this ILog logger, object message, Exception exception)
  488. {
  489. try
  490. {
  491. if (!logger.IsInfoEnabled)
  492. return;
  493. logger.Info(message, exception);
  494. }
  495. catch (Exception ex)
  496. {
  497. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  498. }
  499. }
  500. #endregion
  501. #region info extension that use string format
  502. /// <summary>
  503. /// Logs a formatted message string with the <see cref="Level.Info"/> level.
  504. /// </summary>
  505. /// <param name="logger">The logger on which the message is logged.</param>
  506. /// <param name="format">A String containing zero or more format items</param>
  507. /// <param name="arg0">An Object to format</param>
  508. /// <remarks>
  509. /// <para>
  510. /// The message is formatted using the <c>String.Format</c> method. See
  511. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  512. /// of the formatting.
  513. /// </para>
  514. /// <para>
  515. /// This method does not take an <see cref="Exception"/> object to include in the
  516. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="InfoExt(ILog,object,Exception)"/>
  517. /// methods instead.
  518. /// </para>
  519. /// </remarks>
  520. /// <seealso cref="ILog.Info(object)"/>
  521. /// <seealso cref="ILog.IsInfoEnabled"/>
  522. public static void InfoFormatExt(this ILog logger, string format, object arg0)
  523. {
  524. try
  525. {
  526. if (!logger.IsInfoEnabled)
  527. return;
  528. logger.InfoFormat(format, arg0);
  529. }
  530. catch (Exception ex)
  531. {
  532. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  533. }
  534. }
  535. /// <summary>
  536. /// Logs a formatted message string with the <see cref="Level.Info"/> level.
  537. /// </summary>
  538. /// <param name="logger">The logger on which the message is logged.</param>
  539. /// <param name="format">A String containing zero or more format items</param>
  540. /// <param name="args">An Object array containing zero or more objects to format</param>
  541. /// <remarks>
  542. /// <para>
  543. /// The message is formatted using the <c>String.Format</c> method. See
  544. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  545. /// of the formatting.
  546. /// </para>
  547. /// <para>
  548. /// This method does not take an <see cref="Exception"/> object to include in the
  549. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="InfoExt(ILog,object,Exception)"/>
  550. /// methods instead.
  551. /// </para>
  552. /// </remarks>
  553. /// <seealso cref="ILog.Info(object)"/>
  554. /// <seealso cref="ILog.IsInfoEnabled"/>
  555. public static void InfoFormatExt(this ILog logger, string format, params object[] args)
  556. {
  557. try
  558. {
  559. if (!logger.IsInfoEnabled)
  560. return;
  561. logger.InfoFormat(format, args);
  562. }
  563. catch (Exception ex)
  564. {
  565. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  566. }
  567. }
  568. /// <summary>
  569. /// Logs a formatted message string with the <see cref="Level.Info"/> level.
  570. /// </summary>
  571. /// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
  572. /// <param name="logger">The logger on which the message is logged.</param>
  573. /// <param name="format">A String containing zero or more format items</param>
  574. /// <param name="args">An Object array containing zero or more objects to format</param>
  575. /// <remarks>
  576. /// <para>
  577. /// The message is formatted using the <c>String.Format</c> method. See
  578. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  579. /// of the formatting.
  580. /// </para>
  581. /// <para>
  582. /// This method does not take an <see cref="Exception"/> object to include in the
  583. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="InfoExt(ILog,object,Exception)"/>
  584. /// methods instead.
  585. /// </para>
  586. /// </remarks>
  587. /// <seealso cref="ILog.Info(object)"/>
  588. /// <seealso cref="ILog.IsInfoEnabled"/>
  589. public static void InfoFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args)
  590. {
  591. try
  592. {
  593. if (!logger.IsInfoEnabled)
  594. return;
  595. logger.InfoFormat(provider, format, args);
  596. }
  597. catch (Exception ex)
  598. {
  599. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  600. }
  601. }
  602. /// <summary>
  603. /// Logs a formatted message string with the <see cref="Level.Info"/> level.
  604. /// </summary>
  605. /// <param name="logger">The logger on which the message is logged.</param>
  606. /// <param name="format">A String containing zero or more format items</param>
  607. /// <param name="arg0">An Object to format</param>
  608. /// <param name="arg1">An Object to format</param>
  609. /// <remarks>
  610. /// <para>
  611. /// The message is formatted using the <c>String.Format</c> method. See
  612. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  613. /// of the formatting.
  614. /// </para>
  615. /// <para>
  616. /// This method does not take an <see cref="Exception"/> object to include in the
  617. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="InfoExt(ILog,object,Exception)"/>
  618. /// methods instead.
  619. /// </para>
  620. /// </remarks>
  621. /// <seealso cref="ILog.Info(object)"/>
  622. /// <seealso cref="ILog.IsInfoEnabled"/>
  623. public static void InfoFormatExt(this ILog logger, string format, object arg0, object arg1)
  624. {
  625. try
  626. {
  627. if (!logger.IsInfoEnabled)
  628. return;
  629. logger.InfoFormat(format, arg0, arg1);
  630. }
  631. catch (Exception ex)
  632. {
  633. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  634. }
  635. }
  636. /// <summary>
  637. /// Logs a formatted message string with the <see cref="Level.Info"/> level.
  638. /// </summary>
  639. /// <param name="logger">The logger on which the message is logged.</param>
  640. /// <param name="format">A String containing zero or more format items</param>
  641. /// <param name="arg0">An Object to format</param>
  642. /// <param name="arg1">An Object to format</param>
  643. /// <param name="arg2">An Object to format</param>
  644. /// <remarks>
  645. /// <para>
  646. /// The message is formatted using the <c>String.Format</c> method. See
  647. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  648. /// of the formatting.
  649. /// </para>
  650. /// <para>
  651. /// This method does not take an <see cref="Exception"/> object to include in the
  652. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="InfoExt(ILog,object,Exception)"/>
  653. /// methods instead.
  654. /// </para>
  655. /// </remarks>
  656. /// <seealso cref="ILog.Info(object)"/>
  657. /// <seealso cref="ILog.IsInfoEnabled"/>
  658. public static void InfoFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2)
  659. {
  660. try
  661. {
  662. if (!logger.IsInfoEnabled)
  663. return;
  664. logger.InfoFormat(format, arg0, arg1, arg2);
  665. }
  666. catch (Exception ex)
  667. {
  668. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  669. }
  670. }
  671. #endregion
  672. #endregion
  673. #region warn extensions
  674. #region warn extensions that uses log message lambda expression
  675. /// <summary>
  676. /// Log a message object with the <see cref="Level.Warn"/> level.
  677. /// </summary>
  678. /// <param name="logger">The logger on which the message is logged.</param>
  679. /// <param name="callback">The lambda expression that gets the object to log.</param>
  680. /// <remarks>
  681. /// <para>
  682. /// This method first checks if this logger is <c>WARN</c>
  683. /// enabled by reading the value <seealso cref="ILog.IsWarnEnabled"/> property.
  684. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  685. /// implementation. If this logger is <c>WARN</c> enabled, then it converts
  686. /// the message object (retrieved by invocation of the provided callback) to a
  687. /// string by invoking the appropriate <see cref="log4net.ObjectRenderer.IObjectRenderer"/>.
  688. /// It then proceeds to call all the registered appenders in this logger
  689. /// and also higher in the hierarchy depending on the value of
  690. /// the additivity flag.
  691. /// </para>
  692. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  693. /// to this method will print the name of the <see cref="Exception"/>
  694. /// but no stack trace. To print a stack trace use the
  695. /// <see cref="WarnExt(ILog,Func{object},Exception)"/> form instead.
  696. /// </para>
  697. /// </remarks>
  698. /// <seealso cref="ILog.Warn(object)"/>
  699. /// <seealso cref="ILog.IsWarnEnabled"/>
  700. public static void WarnExt(this ILog logger, Func<object> callback)
  701. {
  702. try
  703. {
  704. if (!logger.IsWarnEnabled)
  705. return;
  706. logger.Warn(callback());
  707. }
  708. catch (Exception ex)
  709. {
  710. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  711. }
  712. }
  713. /// <summary>
  714. /// Log a message object with the <see cref="Level.Warn"/> level including
  715. /// the stack trace of the <see cref="Exception"/> passed
  716. /// as a parameter.
  717. /// </summary>
  718. /// <param name="logger">The logger on which the message is logged.</param>
  719. /// <param name="callback">The lambda expression that gets the object to log.</param>
  720. /// <param name="exception">The exception to log, including its stack trace.</param>
  721. /// <remarks>
  722. /// <para>
  723. /// See the <see cref="WarnExt(ILog, object)"/> form for more detailed information.
  724. /// </para>
  725. /// </remarks>
  726. /// <seealso cref="ILog.Warn(object)"/>
  727. /// <seealso cref="ILog.IsWarnEnabled"/>
  728. public static void WarnExt(this ILog logger, Func<object> callback, Exception exception)
  729. {
  730. try
  731. {
  732. if (!logger.IsWarnEnabled)
  733. return;
  734. logger.Warn(callback(), exception);
  735. }
  736. catch (Exception ex)
  737. {
  738. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  739. }
  740. }
  741. #endregion
  742. #region warn extension that use the formatter
  743. /// <overloads>Log a message object with the <see cref="Level.Warn"/> level.</overloads> //TODO
  744. /// <summary>
  745. /// Log a message object with the <see cref="Level.Warn"/> level.
  746. /// </summary>
  747. /// <param name="logger">The logger on which the message is logged.</param>
  748. /// <param name="message">The message object to log.</param>
  749. /// <remarks>
  750. /// <para>
  751. /// This method first checks if this logger is <c>WARN</c>
  752. /// enabled by reading the value <seealso cref="ILog.IsWarnEnabled"/> property.
  753. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  754. /// implementation. If this logger is <c>WARN</c> enabled, then it converts
  755. /// the message object (passed as parameter) to a string by invoking the appropriate
  756. /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
  757. /// proceeds to call all the registered appenders in this logger
  758. /// and also higher in the hierarchy depending on the value of
  759. /// the additivity flag.
  760. /// </para>
  761. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  762. /// to this method will print the name of the <see cref="Exception"/>
  763. /// but no stack trace. To print a stack trace use the
  764. /// <see cref="WarnExt(ILog,object,Exception)"/> form instead.
  765. /// </para>
  766. /// </remarks>
  767. /// <seealso cref="ILog.Warn(object)"/>
  768. /// <seealso cref="ILog.IsWarnEnabled"/>
  769. public static void WarnExt(this ILog logger, object message)
  770. {
  771. try
  772. {
  773. if (!logger.IsWarnEnabled)
  774. return;
  775. logger.Warn(message);
  776. }
  777. catch (Exception ex)
  778. {
  779. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  780. }
  781. }
  782. /// <summary>
  783. /// Log a message object with the <see cref="Level.Warn"/> level including
  784. /// the stack trace of the <see cref="Exception"/> passed
  785. /// as a parameter.
  786. /// </summary>
  787. /// <param name="logger">The logger on which the message is logged.</param>
  788. /// <param name="message">The message object to log.</param>
  789. /// <param name="exception">The exception to log, including its stack trace.</param>
  790. /// <remarks>
  791. /// <para>
  792. /// See the <see cref="WarnExt(ILog, object)"/> form for more detailed information.
  793. /// </para>
  794. /// </remarks>
  795. /// <seealso cref="ILog.Warn(object)"/>
  796. /// <seealso cref="ILog.IsWarnEnabled"/>
  797. public static void WarnExt(this ILog logger, object message, Exception exception)
  798. {
  799. try
  800. {
  801. if (!logger.IsWarnEnabled)
  802. return;
  803. logger.Warn(message, exception);
  804. }
  805. catch (Exception ex)
  806. {
  807. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  808. }
  809. }
  810. #endregion
  811. #region warn extension that use string format
  812. /// <summary>
  813. /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
  814. /// </summary>
  815. /// <param name="logger">The logger on which the message is logged.</param>
  816. /// <param name="format">A String containing zero or more format items</param>
  817. /// <param name="arg0">An Object 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="WarnExt(ILog,object,Exception)"/>
  827. /// methods instead.
  828. /// </para>
  829. /// </remarks>
  830. /// <seealso cref="ILog.Warn(object)"/>
  831. /// <seealso cref="ILog.IsWarnEnabled"/>
  832. public static void WarnFormatExt(this ILog logger, string format, object arg0)
  833. {
  834. try
  835. {
  836. if (!logger.IsWarnEnabled)
  837. return;
  838. logger.WarnFormat(format, arg0);
  839. }
  840. catch (Exception ex)
  841. {
  842. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  843. }
  844. }
  845. /// <summary>
  846. /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
  847. /// </summary>
  848. /// <param name="logger">The logger on which the message is logged.</param>
  849. /// <param name="format">A String containing zero or more format items</param>
  850. /// <param name="args">An Object array containing zero or more objects to format</param>
  851. /// <remarks>
  852. /// <para>
  853. /// The message is formatted using the <c>String.Format</c> method. See
  854. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  855. /// of the formatting.
  856. /// </para>
  857. /// <para>
  858. /// This method does not take an <see cref="Exception"/> object to include in the
  859. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="WarnExt(ILog,object,Exception)"/>
  860. /// methods instead.
  861. /// </para>
  862. /// </remarks>
  863. /// <seealso cref="ILog.Warn(object)"/>
  864. /// <seealso cref="ILog.IsWarnEnabled"/>
  865. public static void WarnFormatExt(this ILog logger, string format, params object[] args)
  866. {
  867. try
  868. {
  869. if (!logger.IsWarnEnabled)
  870. return;
  871. logger.WarnFormat(format, args);
  872. }
  873. catch (Exception ex)
  874. {
  875. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  876. }
  877. }
  878. /// <summary>
  879. /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
  880. /// </summary>
  881. /// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
  882. /// <param name="logger">The logger on which the message is logged.</param>
  883. /// <param name="format">A String containing zero or more format items</param>
  884. /// <param name="args">An Object array containing zero or more objects to format</param>
  885. /// <remarks>
  886. /// <para>
  887. /// The message is formatted using the <c>String.Format</c> method. See
  888. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  889. /// of the formatting.
  890. /// </para>
  891. /// <para>
  892. /// This method does not take an <see cref="Exception"/> object to include in the
  893. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="WarnExt(ILog,object,Exception)"/>
  894. /// methods instead.
  895. /// </para>
  896. /// </remarks>
  897. /// <seealso cref="ILog.Warn(object)"/>
  898. /// <seealso cref="ILog.IsWarnEnabled"/>
  899. public static void WarnFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args)
  900. {
  901. try
  902. {
  903. if (!logger.IsWarnEnabled)
  904. return;
  905. logger.WarnFormat(provider, format, args);
  906. }
  907. catch (Exception ex)
  908. {
  909. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  910. }
  911. }
  912. /// <summary>
  913. /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
  914. /// </summary>
  915. /// <param name="logger">The logger on which the message is logged.</param>
  916. /// <param name="format">A String containing zero or more format items</param>
  917. /// <param name="arg0">An Object to format</param>
  918. /// <param name="arg1">An Object to format</param>
  919. /// <remarks>
  920. /// <para>
  921. /// The message is formatted using the <c>String.Format</c> method. See
  922. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  923. /// of the formatting.
  924. /// </para>
  925. /// <para>
  926. /// This method does not take an <see cref="Exception"/> object to include in the
  927. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="WarnExt(ILog,object,Exception)"/>
  928. /// methods instead.
  929. /// </para>
  930. /// </remarks>
  931. /// <seealso cref="ILog.Warn(object)"/>
  932. /// <seealso cref="ILog.IsWarnEnabled"/>
  933. public static void WarnFormatExt(this ILog logger, string format, object arg0, object arg1)
  934. {
  935. try
  936. {
  937. if (!logger.IsWarnEnabled)
  938. return;
  939. logger.WarnFormat(format, arg0, arg1);
  940. }
  941. catch (Exception ex)
  942. {
  943. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  944. }
  945. }
  946. /// <summary>
  947. /// Logs a formatted message string with the <see cref="Level.Warn"/> level.
  948. /// </summary>
  949. /// <param name="logger">The logger on which the message is logged.</param>
  950. /// <param name="format">A String containing zero or more format items</param>
  951. /// <param name="arg0">An Object to format</param>
  952. /// <param name="arg1">An Object to format</param>
  953. /// <param name="arg2">An Object to format</param>
  954. /// <remarks>
  955. /// <para>
  956. /// The message is formatted using the <c>String.Format</c> method. See
  957. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  958. /// of the formatting.
  959. /// </para>
  960. /// <para>
  961. /// This method does not take an <see cref="Exception"/> object to include in the
  962. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="WarnExt(ILog,object,Exception)"/>
  963. /// methods instead.
  964. /// </para>
  965. /// </remarks>
  966. /// <seealso cref="ILog.Warn(object)"/>
  967. /// <seealso cref="ILog.IsWarnEnabled"/>
  968. public static void WarnFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2)
  969. {
  970. try
  971. {
  972. if (!logger.IsWarnEnabled)
  973. return;
  974. logger.WarnFormat(format, arg0, arg1, arg2);
  975. }
  976. catch (Exception ex)
  977. {
  978. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  979. }
  980. }
  981. #endregion
  982. #endregion
  983. #region error extensions
  984. #region error extensions that uses log message lambda expression
  985. /// <summary>
  986. /// Log a message object with the <see cref="Level.Error"/> level.
  987. /// </summary>
  988. /// <param name="logger">The logger on which the message is logged.</param>
  989. /// <param name="callback">The lambda expression that gets the object to log.</param>
  990. /// <remarks>
  991. /// <para>
  992. /// This method first checks if this logger is <c>ERROR</c>
  993. /// enabled by reading the value <seealso cref="ILog.IsErrorEnabled"/> property.
  994. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  995. /// implementation. If this logger is <c>ERROR</c> enabled, then it converts
  996. /// the message object (retrieved by invocation of the provided callback) to a
  997. /// string by invoking the appropriate <see cref="log4net.ObjectRenderer.IObjectRenderer"/>.
  998. /// It then proceeds to call all the registered appenders in this logger
  999. /// and also higher in the hierarchy depending on the value of
  1000. /// the additivity flag.
  1001. /// </para>
  1002. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  1003. /// to this method will print the name of the <see cref="Exception"/>
  1004. /// but no stack trace. To print a stack trace use the
  1005. /// <see cref="ErrorExt(ILog,Func{object},Exception)"/> form instead.
  1006. /// </para>
  1007. /// </remarks>
  1008. /// <seealso cref="ILog.Error(object)"/>
  1009. /// <seealso cref="ILog.IsErrorEnabled"/>
  1010. public static void ErrorExt(this ILog logger, Func<object> callback)
  1011. {
  1012. try
  1013. {
  1014. if (!logger.IsErrorEnabled)
  1015. return;
  1016. logger.Error(callback());
  1017. }
  1018. catch (Exception ex)
  1019. {
  1020. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1021. }
  1022. }
  1023. /// <summary>
  1024. /// Log a message object with the <see cref="Level.Error"/> level including
  1025. /// the stack trace of the <see cref="Exception"/> passed
  1026. /// as a parameter.
  1027. /// </summary>
  1028. /// <param name="logger">The logger on which the message is logged.</param>
  1029. /// <param name="callback">The lambda expression that gets the object to log.</param>
  1030. /// <param name="exception">The exception to log, including its stack trace.</param>
  1031. /// <remarks>
  1032. /// <para>
  1033. /// See the <see cref="ErrorExt(ILog, object)"/> form for more detailed information.
  1034. /// </para>
  1035. /// </remarks>
  1036. /// <seealso cref="ILog.Error(object)"/>
  1037. /// <seealso cref="ILog.IsErrorEnabled"/>
  1038. public static void ErrorExt(this ILog logger, Func<object> callback, Exception exception)
  1039. {
  1040. try
  1041. {
  1042. if (!logger.IsErrorEnabled)
  1043. return;
  1044. logger.Error(callback(), exception);
  1045. }
  1046. catch (Exception ex)
  1047. {
  1048. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1049. }
  1050. }
  1051. #endregion
  1052. #region error extension that use the formatter
  1053. /// <overloads>Log a message object with the <see cref="Level.Error"/> level.</overloads> //TODO
  1054. /// <summary>
  1055. /// Log a message object with the <see cref="Level.Error"/> level.
  1056. /// </summary>
  1057. /// <param name="logger">The logger on which the message is logged.</param>
  1058. /// <param name="message">The message object to log.</param>
  1059. /// <remarks>
  1060. /// <para>
  1061. /// This method first checks if this logger is <c>ERROR</c>
  1062. /// enabled by reading the value <seealso cref="ILog.IsErrorEnabled"/> property.
  1063. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  1064. /// implementation. If this logger is <c>ERROR</c> enabled, then it converts
  1065. /// the message object (passed as parameter) to a string by invoking the appropriate
  1066. /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
  1067. /// proceeds to call all the registered appenders in this logger
  1068. /// and also higher in the hierarchy depending on the value of
  1069. /// the additivity flag.
  1070. /// </para>
  1071. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  1072. /// to this method will print the name of the <see cref="Exception"/>
  1073. /// but no stack trace. To print a stack trace use the
  1074. /// <see cref="ErrorExt(ILog,object,Exception)"/> form instead.
  1075. /// </para>
  1076. /// </remarks>
  1077. /// <seealso cref="ILog.Error(object)"/>
  1078. /// <seealso cref="ILog.IsErrorEnabled"/>
  1079. public static void ErrorExt(this ILog logger, object message)
  1080. {
  1081. try
  1082. {
  1083. if (!logger.IsErrorEnabled)
  1084. return;
  1085. logger.Error(message);
  1086. }
  1087. catch (Exception ex)
  1088. {
  1089. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1090. }
  1091. }
  1092. /// <summary>
  1093. /// Log a message object with the <see cref="Level.Error"/> level including
  1094. /// the stack trace of the <see cref="Exception"/> passed
  1095. /// as a parameter.
  1096. /// </summary>
  1097. /// <param name="logger">The logger on which the message is logged.</param>
  1098. /// <param name="message">The message object to log.</param>
  1099. /// <param name="exception">The exception to log, including its stack trace.</param>
  1100. /// <remarks>
  1101. /// <para>
  1102. /// See the <see cref="ErrorExt(ILog, object)"/> form for more detailed information.
  1103. /// </para>
  1104. /// </remarks>
  1105. /// <seealso cref="ILog.Error(object)"/>
  1106. /// <seealso cref="ILog.IsErrorEnabled"/>
  1107. public static void ErrorExt(this ILog logger, object message, Exception exception)
  1108. {
  1109. try
  1110. {
  1111. if (!logger.IsErrorEnabled)
  1112. return;
  1113. logger.Error(message, exception);
  1114. }
  1115. catch (Exception ex)
  1116. {
  1117. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1118. }
  1119. }
  1120. #endregion
  1121. #region error extension that use string format
  1122. /// <summary>
  1123. /// Logs a formatted message string with the <see cref="Level.Error"/> level.
  1124. /// </summary>
  1125. /// <param name="logger">The logger on which the message is logged.</param>
  1126. /// <param name="format">A String containing zero or more format items</param>
  1127. /// <param name="arg0">An Object to format</param>
  1128. /// <remarks>
  1129. /// <para>
  1130. /// The message is formatted using the <c>String.Format</c> method. See
  1131. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1132. /// of the formatting.
  1133. /// </para>
  1134. /// <para>
  1135. /// This method does not take an <see cref="Exception"/> object to include in the
  1136. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="ErrorExt(ILog,object,Exception)"/>
  1137. /// methods instead.
  1138. /// </para>
  1139. /// </remarks>
  1140. /// <seealso cref="ILog.Error(object)"/>
  1141. /// <seealso cref="ILog.IsErrorEnabled"/>
  1142. public static void ErrorFormatExt(this ILog logger, string format, object arg0)
  1143. {
  1144. try
  1145. {
  1146. if (!logger.IsErrorEnabled)
  1147. return;
  1148. logger.ErrorFormat(format, arg0);
  1149. }
  1150. catch (Exception ex)
  1151. {
  1152. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1153. }
  1154. }
  1155. /// <summary>
  1156. /// Logs a formatted message string with the <see cref="Level.Error"/> level.
  1157. /// </summary>
  1158. /// <param name="logger">The logger on which the message is logged.</param>
  1159. /// <param name="format">A String containing zero or more format items</param>
  1160. /// <param name="args">An Object array containing zero or more objects to format</param>
  1161. /// <remarks>
  1162. /// <para>
  1163. /// The message is formatted using the <c>String.Format</c> method. See
  1164. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1165. /// of the formatting.
  1166. /// </para>
  1167. /// <para>
  1168. /// This method does not take an <see cref="Exception"/> object to include in the
  1169. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="ErrorExt(ILog,object,Exception)"/>
  1170. /// methods instead.
  1171. /// </para>
  1172. /// </remarks>
  1173. /// <seealso cref="ILog.Error(object)"/>
  1174. /// <seealso cref="ILog.IsErrorEnabled"/>
  1175. public static void ErrorFormatExt(this ILog logger, string format, params object[] args)
  1176. {
  1177. try
  1178. {
  1179. if (!logger.IsErrorEnabled)
  1180. return;
  1181. logger.ErrorFormat(format, args);
  1182. }
  1183. catch (Exception ex)
  1184. {
  1185. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1186. }
  1187. }
  1188. /// <summary>
  1189. /// Logs a formatted message string with the <see cref="Level.Error"/> level.
  1190. /// </summary>
  1191. /// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
  1192. /// <param name="logger">The logger on which the message is logged.</param>
  1193. /// <param name="format">A String containing zero or more format items</param>
  1194. /// <param name="args">An Object array containing zero or more objects to format</param>
  1195. /// <remarks>
  1196. /// <para>
  1197. /// The message is formatted using the <c>String.Format</c> method. See
  1198. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1199. /// of the formatting.
  1200. /// </para>
  1201. /// <para>
  1202. /// This method does not take an <see cref="Exception"/> object to include in the
  1203. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="ErrorExt(ILog,object,Exception)"/>
  1204. /// methods instead.
  1205. /// </para>
  1206. /// </remarks>
  1207. /// <seealso cref="ILog.Error(object)"/>
  1208. /// <seealso cref="ILog.IsErrorEnabled"/>
  1209. public static void ErrorFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args)
  1210. {
  1211. try
  1212. {
  1213. if (!logger.IsErrorEnabled)
  1214. return;
  1215. logger.ErrorFormat(provider, format, args);
  1216. }
  1217. catch (Exception ex)
  1218. {
  1219. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1220. }
  1221. }
  1222. /// <summary>
  1223. /// Logs a formatted message string with the <see cref="Level.Error"/> level.
  1224. /// </summary>
  1225. /// <param name="logger">The logger on which the message is logged.</param>
  1226. /// <param name="format">A String containing zero or more format items</param>
  1227. /// <param name="arg0">An Object to format</param>
  1228. /// <param name="arg1">An Object to format</param>
  1229. /// <remarks>
  1230. /// <para>
  1231. /// The message is formatted using the <c>String.Format</c> method. See
  1232. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1233. /// of the formatting.
  1234. /// </para>
  1235. /// <para>
  1236. /// This method does not take an <see cref="Exception"/> object to include in the
  1237. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="ErrorExt(ILog,object,Exception)"/>
  1238. /// methods instead.
  1239. /// </para>
  1240. /// </remarks>
  1241. /// <seealso cref="ILog.Error(object)"/>
  1242. /// <seealso cref="ILog.IsErrorEnabled"/>
  1243. public static void ErrorFormatExt(this ILog logger, string format, object arg0, object arg1)
  1244. {
  1245. try
  1246. {
  1247. if (!logger.IsErrorEnabled)
  1248. return;
  1249. logger.ErrorFormat(format, arg0, arg1);
  1250. }
  1251. catch (Exception ex)
  1252. {
  1253. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1254. }
  1255. }
  1256. /// <summary>
  1257. /// Logs a formatted message string with the <see cref="Level.Error"/> level.
  1258. /// </summary>
  1259. /// <param name="logger">The logger on which the message is logged.</param>
  1260. /// <param name="format">A String containing zero or more format items</param>
  1261. /// <param name="arg0">An Object to format</param>
  1262. /// <param name="arg1">An Object to format</param>
  1263. /// <param name="arg2">An Object to format</param>
  1264. /// <remarks>
  1265. /// <para>
  1266. /// The message is formatted using the <c>String.Format</c> method. See
  1267. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1268. /// of the formatting.
  1269. /// </para>
  1270. /// <para>
  1271. /// This method does not take an <see cref="Exception"/> object to include in the
  1272. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="ErrorExt(ILog,object,Exception)"/>
  1273. /// methods instead.
  1274. /// </para>
  1275. /// </remarks>
  1276. /// <seealso cref="ILog.Error(object)"/>
  1277. /// <seealso cref="ILog.IsErrorEnabled"/>
  1278. public static void ErrorFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2)
  1279. {
  1280. try
  1281. {
  1282. if (!logger.IsErrorEnabled)
  1283. return;
  1284. logger.ErrorFormat(format, arg0, arg1, arg2);
  1285. }
  1286. catch (Exception ex)
  1287. {
  1288. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1289. }
  1290. }
  1291. #endregion
  1292. #endregion
  1293. #region fatal extensions
  1294. #region fatal extensions that uses log message lambda expression
  1295. /// <summary>
  1296. /// Log a message object with the <see cref="Level.Fatal"/> level.
  1297. /// </summary>
  1298. /// <param name="logger">The logger on which the message is logged.</param>
  1299. /// <param name="callback">The lambda expression that gets the object to log.</param>
  1300. /// <remarks>
  1301. /// <para>
  1302. /// This method first checks if this logger is <c>FATAL</c>
  1303. /// enabled by reading the value <seealso cref="ILog.IsFatalEnabled"/> property.
  1304. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  1305. /// implementation. If this logger is <c>FATAL</c> enabled, then it converts
  1306. /// the message object (retrieved by invocation of the provided callback) to a
  1307. /// string by invoking the appropriate <see cref="log4net.ObjectRenderer.IObjectRenderer"/>.
  1308. /// It then proceeds to call all the registered appenders in this logger
  1309. /// and also higher in the hierarchy depending on the value of
  1310. /// the additivity flag.
  1311. /// </para>
  1312. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  1313. /// to this method will print the name of the <see cref="Exception"/>
  1314. /// but no stack trace. To print a stack trace use the
  1315. /// <see cref="FatalExt(ILog,Func{object},Exception)"/> form instead.
  1316. /// </para>
  1317. /// </remarks>
  1318. /// <seealso cref="ILog.Fatal(object)"/>
  1319. /// <seealso cref="ILog.IsFatalEnabled"/>
  1320. public static void FatalExt(this ILog logger, Func<object> callback)
  1321. {
  1322. try
  1323. {
  1324. if (!logger.IsFatalEnabled)
  1325. return;
  1326. logger.Fatal(callback());
  1327. }
  1328. catch (Exception ex)
  1329. {
  1330. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1331. }
  1332. }
  1333. /// <summary>
  1334. /// Log a message object with the <see cref="Level.Fatal"/> level including
  1335. /// the stack trace of the <see cref="Exception"/> passed
  1336. /// as a parameter.
  1337. /// </summary>
  1338. /// <param name="logger">The logger on which the message is logged.</param>
  1339. /// <param name="callback">The lambda expression that gets the object to log.</param>
  1340. /// <param name="exception">The exception to log, including its stack trace.</param>
  1341. /// <remarks>
  1342. /// <para>
  1343. /// See the <see cref="FatalExt(ILog, object)"/> form for more detailed information.
  1344. /// </para>
  1345. /// </remarks>
  1346. /// <seealso cref="ILog.Fatal(object)"/>
  1347. /// <seealso cref="ILog.IsFatalEnabled"/>
  1348. public static void FatalExt(this ILog logger, Func<object> callback, Exception exception)
  1349. {
  1350. try
  1351. {
  1352. if (!logger.IsFatalEnabled)
  1353. return;
  1354. logger.Fatal(callback(), exception);
  1355. }
  1356. catch (Exception ex)
  1357. {
  1358. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1359. }
  1360. }
  1361. #endregion
  1362. #region fatal extension that use the formatter
  1363. /// <overloads>Log a message object with the <see cref="Level.Fatal"/> level.</overloads> //TODO
  1364. /// <summary>
  1365. /// Log a message object with the <see cref="Level.Fatal"/> level.
  1366. /// </summary>
  1367. /// <param name="logger">The logger on which the message is logged.</param>
  1368. /// <param name="message">The message object to log.</param>
  1369. /// <remarks>
  1370. /// <para>
  1371. /// This method first checks if this logger is <c>FATAL</c>
  1372. /// enabled by reading the value <seealso cref="ILog.IsFatalEnabled"/> property.
  1373. /// This check happens always and does not depend on the <seealso cref="ILog"/>
  1374. /// implementation. If this logger is <c>FATAL</c> enabled, then it converts
  1375. /// the message object (passed as parameter) to a string by invoking the appropriate
  1376. /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then
  1377. /// proceeds to call all the registered appenders in this logger
  1378. /// and also higher in the hierarchy depending on the value of
  1379. /// the additivity flag.
  1380. /// </para>
  1381. /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/>
  1382. /// to this method will print the name of the <see cref="Exception"/>
  1383. /// but no stack trace. To print a stack trace use the
  1384. /// <see cref="FatalExt(ILog,object,Exception)"/> form instead.
  1385. /// </para>
  1386. /// </remarks>
  1387. /// <seealso cref="ILog.Fatal(object)"/>
  1388. /// <seealso cref="ILog.IsFatalEnabled"/>
  1389. public static void FatalExt(this ILog logger, object message)
  1390. {
  1391. try
  1392. {
  1393. if (!logger.IsFatalEnabled)
  1394. return;
  1395. logger.Fatal(message);
  1396. }
  1397. catch (Exception ex)
  1398. {
  1399. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1400. }
  1401. }
  1402. /// <summary>
  1403. /// Log a message object with the <see cref="Level.Fatal"/> level including
  1404. /// the stack trace of the <see cref="Exception"/> passed
  1405. /// as a parameter.
  1406. /// </summary>
  1407. /// <param name="logger">The logger on which the message is logged.</param>
  1408. /// <param name="message">The message object to log.</param>
  1409. /// <param name="exception">The exception to log, including its stack trace.</param>
  1410. /// <remarks>
  1411. /// <para>
  1412. /// See the <see cref="FatalExt(ILog, object)"/> form for more detailed information.
  1413. /// </para>
  1414. /// </remarks>
  1415. /// <seealso cref="ILog.Fatal(object)"/>
  1416. /// <seealso cref="ILog.IsFatalEnabled"/>
  1417. public static void FatalExt(this ILog logger, object message, Exception exception)
  1418. {
  1419. try
  1420. {
  1421. if (!logger.IsFatalEnabled)
  1422. return;
  1423. logger.Fatal(message, exception);
  1424. }
  1425. catch (Exception ex)
  1426. {
  1427. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1428. }
  1429. }
  1430. #endregion
  1431. #region fatal extension that use string format
  1432. /// <summary>
  1433. /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
  1434. /// </summary>
  1435. /// <param name="logger">The logger on which the message is logged.</param>
  1436. /// <param name="format">A String containing zero or more format items</param>
  1437. /// <param name="arg0">An Object to format</param>
  1438. /// <remarks>
  1439. /// <para>
  1440. /// The message is formatted using the <c>String.Format</c> method. See
  1441. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1442. /// of the formatting.
  1443. /// </para>
  1444. /// <para>
  1445. /// This method does not take an <see cref="Exception"/> object to include in the
  1446. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="FatalExt(ILog,object,Exception)"/>
  1447. /// methods instead.
  1448. /// </para>
  1449. /// </remarks>
  1450. /// <seealso cref="ILog.Fatal(object)"/>
  1451. /// <seealso cref="ILog.IsFatalEnabled"/>
  1452. public static void FatalFormatExt(this ILog logger, string format, object arg0)
  1453. {
  1454. try
  1455. {
  1456. if (!logger.IsFatalEnabled)
  1457. return;
  1458. logger.FatalFormat(format, arg0);
  1459. }
  1460. catch (Exception ex)
  1461. {
  1462. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1463. }
  1464. }
  1465. /// <summary>
  1466. /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
  1467. /// </summary>
  1468. /// <param name="logger">The logger on which the message is logged.</param>
  1469. /// <param name="format">A String containing zero or more format items</param>
  1470. /// <param name="args">An Object array containing zero or more objects to format</param>
  1471. /// <remarks>
  1472. /// <para>
  1473. /// The message is formatted using the <c>String.Format</c> method. See
  1474. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1475. /// of the formatting.
  1476. /// </para>
  1477. /// <para>
  1478. /// This method does not take an <see cref="Exception"/> object to include in the
  1479. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="FatalExt(ILog,object,Exception)"/>
  1480. /// methods instead.
  1481. /// </para>
  1482. /// </remarks>
  1483. /// <seealso cref="ILog.Fatal(object)"/>
  1484. /// <seealso cref="ILog.IsFatalEnabled"/>
  1485. public static void FatalFormatExt(this ILog logger, string format, params object[] args)
  1486. {
  1487. try
  1488. {
  1489. if (!logger.IsFatalEnabled)
  1490. return;
  1491. logger.FatalFormat(format, args);
  1492. }
  1493. catch (Exception ex)
  1494. {
  1495. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1496. }
  1497. }
  1498. /// <summary>
  1499. /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
  1500. /// </summary>
  1501. /// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information</param>
  1502. /// <param name="logger">The logger on which the message is logged.</param>
  1503. /// <param name="format">A String containing zero or more format items</param>
  1504. /// <param name="args">An Object array containing zero or more objects to format</param>
  1505. /// <remarks>
  1506. /// <para>
  1507. /// The message is formatted using the <c>String.Format</c> method. See
  1508. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1509. /// of the formatting.
  1510. /// </para>
  1511. /// <para>
  1512. /// This method does not take an <see cref="Exception"/> object to include in the
  1513. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="FatalExt(ILog,object,Exception)"/>
  1514. /// methods instead.
  1515. /// </para>
  1516. /// </remarks>
  1517. /// <seealso cref="ILog.Fatal(object)"/>
  1518. /// <seealso cref="ILog.IsFatalEnabled"/>
  1519. public static void FatalFormatExt(this ILog logger, IFormatProvider provider, string format, params object[] args)
  1520. {
  1521. try
  1522. {
  1523. if (!logger.IsFatalEnabled)
  1524. return;
  1525. logger.FatalFormat(provider, format, args);
  1526. }
  1527. catch (Exception ex)
  1528. {
  1529. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1530. }
  1531. }
  1532. /// <summary>
  1533. /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
  1534. /// </summary>
  1535. /// <param name="logger">The logger on which the message is logged.</param>
  1536. /// <param name="format">A String containing zero or more format items</param>
  1537. /// <param name="arg0">An Object to format</param>
  1538. /// <param name="arg1">An Object to format</param>
  1539. /// <remarks>
  1540. /// <para>
  1541. /// The message is formatted using the <c>String.Format</c> method. See
  1542. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1543. /// of the formatting.
  1544. /// </para>
  1545. /// <para>
  1546. /// This method does not take an <see cref="Exception"/> object to include in the
  1547. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="FatalExt(ILog,object,Exception)"/>
  1548. /// methods instead.
  1549. /// </para>
  1550. /// </remarks>
  1551. /// <seealso cref="ILog.Fatal(object)"/>
  1552. /// <seealso cref="ILog.IsFatalEnabled"/>
  1553. public static void FatalFormatExt(this ILog logger, string format, object arg0, object arg1)
  1554. {
  1555. try
  1556. {
  1557. if (!logger.IsFatalEnabled)
  1558. return;
  1559. logger.FatalFormat(format, arg0, arg1);
  1560. }
  1561. catch (Exception ex)
  1562. {
  1563. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1564. }
  1565. }
  1566. /// <summary>
  1567. /// Logs a formatted message string with the <see cref="Level.Fatal"/> level.
  1568. /// </summary>
  1569. /// <param name="logger">The logger on which the message is logged.</param>
  1570. /// <param name="format">A String containing zero or more format items</param>
  1571. /// <param name="arg0">An Object to format</param>
  1572. /// <param name="arg1">An Object to format</param>
  1573. /// <param name="arg2">An Object to format</param>
  1574. /// <remarks>
  1575. /// <para>
  1576. /// The message is formatted using the <c>String.Format</c> method. See
  1577. /// <see cref="String.Format(string, object[])"/> for details of the syntax of the format string and the behavior
  1578. /// of the formatting.
  1579. /// </para>
  1580. /// <para>
  1581. /// This method does not take an <see cref="Exception"/> object to include in the
  1582. /// log event. To pass an <see cref="Exception"/> use one of the <see cref="FatalExt(ILog,object,Exception)"/>
  1583. /// methods instead.
  1584. /// </para>
  1585. /// </remarks>
  1586. /// <seealso cref="ILog.Fatal(object)"/>
  1587. /// <seealso cref="ILog.IsFatalEnabled"/>
  1588. public static void FatalFormatExt(this ILog logger, string format, object arg0, object arg1, object arg2)
  1589. {
  1590. try
  1591. {
  1592. if (!logger.IsFatalEnabled)
  1593. return;
  1594. logger.FatalFormat(format, arg0, arg1, arg2);
  1595. }
  1596. catch (Exception ex)
  1597. {
  1598. log4net.Util.LogLog.Error(declaringType, "Exception while logging", ex);
  1599. }
  1600. }
  1601. #endregion
  1602. #endregion
  1603. }
  1604. }
  1605. #endif