Created
June 6, 2012 20:19
-
-
Save mauricio/2884497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Common.Logging { | |
| public static class Extensions { | |
| public delegate string PrinterDelegate( string pattern, params object[] args ); | |
| public static void Debug (this ILog logger, Func<PrinterDelegate,string> printer) | |
| { | |
| if (logger.IsDebugEnabled) { | |
| logger.Debug (printer (PrintLog)); | |
| } | |
| } | |
| public static void Debug (this ILog logger, Func<PrinterDelegate,string> printer, Exception exception) | |
| { | |
| if (logger.IsDebugEnabled) { | |
| logger.Debug (printer (PrintLog), exception); | |
| } | |
| } | |
| public static void Info (this ILog logger, Func<PrinterDelegate,string> printer) | |
| { | |
| if (logger.IsInfoEnabled) { | |
| logger.Info( printer(PrintLog) ); | |
| } | |
| } | |
| public static void Info (this ILog logger, Func<PrinterDelegate,string> printer, Exception exception) | |
| { | |
| if (logger.IsInfoEnabled) { | |
| logger.Info (printer (PrintLog), exception); | |
| } | |
| } | |
| public static void Fatal (this ILog logger, Func<PrinterDelegate,string> printer) | |
| { | |
| if (logger.IsFatalEnabled) { | |
| logger.Fatal (printer (PrintLog)); | |
| } | |
| } | |
| public static void Fatal (this ILog logger, Func<PrinterDelegate,string> printer, Exception e) | |
| { | |
| if (logger.IsFatalEnabled) { | |
| object message = printer (PrintLog); | |
| logger.Fatal (message, e); | |
| } | |
| } | |
| public static string PrintLog( string pattern, params object[] args ) { | |
| return String.Format( pattern, args ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment