是否有一种允许创建多个实例的类单例模式的实现?
我的班级定义是:
public class Logger
{
private Logger(string logPath)
{
this.logPath = logPath;
}
/// <summary>
/// Creates singleton
/// </summary>
/// <param name="logPath"></param>
/// <returns></returns>
public static Logger GetInstance(string logPath)
{
lock (instanceLock)
{
if (logger == null)
{
logger = new Logger(logPath);
}
}
return logger;
}
public static Logger Instance()
{
return logger;
}
/// <summary>
/// Destructor
/// </summary>
~Logger()
{
try
{
this.Close();
}
catch (Exception)
{
}
}
}