Skip to content

Instantly share code, notes, and snippets.

@chrissie1
Created December 15, 2012 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrissie1/4299744 to your computer and use it in GitHub Desktop.
Save chrissie1/4299744 to your computer and use it in GitHub Desktop.
This should work but needs some locking on the set.
internal static class Container
{
private static class PerType<T>
{
public static ILog Log;
}
public static ILog GetOrAdd<T>()
{
var log = PerType<T>.Log;
if (log == null)
{
Console.WriteLine("new log");
PerType<T>.Log = new Log1();
log = PerType<T>.Log;
}
Console.WriteLine("return log");
return log;
}
}
public static class LogExtensions
{
public static ILog Log<T>(this T type)
{
return Container.GetOrAdd<T>();
}
}
@ferventcoder
Copy link

Yes, you absolutely could set a container. I might name it something different though since it's only purpose is to hold ILog objects.

I think you may have also missed what I updated, which is that the static gateway ALWAYS returns a new object unless it is initialized with a test logger.

@ferventcoder
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment