获取文件(防锁占用)

 


/****获取文件(防锁占用)*****/
/// <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;
}

posted @ 2016-05-17 13:42  FiberHomer  阅读(194)  评论(0编辑  收藏  举报