Created
December 15, 2012 22:09
-
-
Save chrissie1/4299744 to your computer and use it in GitHub Desktop.
This should work but needs some locking on the set.
This file contains 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
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>(); | |
} | |
} |
I've updated this for more readability here: https://github.com/ferventcoder/this.Log/blob/master/LoggingExtensions.Core/Logging/Log.cs#L44
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.