I believe the first example code is a short-term implementation of Singleton, and I'm not sure if it is thread safe. As a class, an EventSourceLogger comes from an EventSource that is not static, this class cannot be just a static class (which would be even more convenient - a trade-off between singlet and static regardless).
I returned from a more thorough concrete well-known thread safe implementation to this implementation for brevity - after you fell in love with the look of this approach in your peers code. What have I lost?
Current implementation
[EventSource(Name = "EventSourceLogger")] public class EventSourceLogger : EventSource { public static readonly EventSourceLogger Logger = new EventSourceLogger();` }
Previous implementation
[EventSource(Name = "EventSourceLogger")] public class EventSourceLogger : EventSource { private static EventSourceLogger instance; private EventSourceLogger() { } public static EventSourceLogger Instance { get { if (instance == null) { instance = new EventSourceLogger(); } return instance; } } }
source share