Skip to content

Instantly share code, notes, and snippets.

@skalinets
Created July 7, 2011 15:10
Show Gist options
  • Save skalinets/1069722 to your computer and use it in GitHub Desktop.
Save skalinets/1069722 to your computer and use it in GitHub Desktop.
// declaration
public class ServiceLogger : IServiceLogger
{
private readonly ILog log;
public ServiceLogger(object o)
{
log = LogManager.GetLogger(o.GetType().Name);
}
public void Write(string message, params object[] args)
{
log.InfoFormat(message, args);
}
public void WriteToExceptionCategory(string message, params object[] args)
{
log.ErrorFormat(message, args);
}
}
public static class LoggerExtensions
{
public static IServiceLogger GetLogger(this object o)
{
return new ServiceLogger(o);
}
}
// usage
this.GetLogger().WriteToExceptionCategory("Error while opening connection: {0}", ex.Message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment