Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Dec 18, 2012

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

This comment has been minimized.

Copy link

commented Dec 18, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.