Skip to content

Instantly share code, notes, and snippets.

@mauricio
Created June 6, 2012 20:19
Show Gist options
  • Select an option

  • Save mauricio/2884497 to your computer and use it in GitHub Desktop.

Select an option

Save mauricio/2884497 to your computer and use it in GitHub Desktop.
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