获取文件(防锁占用)


/****获取文件(防锁占用)*****/
/// <summary>
/// 获取文件路径
/// </summary>
/// <returns></returns>
private string GetFilePath()
{
string directory = Path.Combine(Application.StartupPath, "TestLog");

if (!Directory.Exists(directory))
{
lock (_lockObj)
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
}
}

string path = Path.Combine(directory, string.Format("{0:yyyy-MM-dd}.log", DateTime.Now));

return path;
}

原文地址:https://www.cnblogs.com/Robert-huge/p/5501325.html