public static LogSingleton log() { if (instance == null) { /** * The client who has s_lock will proceed this condition. */ lock (s_lock) { /** * I will assign the singleton instance if instance is null. * otherwise will return directly. */ if (instance == null) { instance = new LogSingleton(); } } } return(instance); }
static void Main(string[] args) { var client = LogSingleton.log(); // this is the singleton instance. Console.WriteLine(client.debugLog()); }