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>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated this for more readability here: https://github.com/ferventcoder/this.Log/blob/master/LoggingExtensions.Core/Logging/Log.cs#L44