日期:2014-05-17  浏览次数:20538 次

The process cannot access the file because it is being used by another process
public void WriteLogToLocal(string v_Msg, string lx)
        {
            try
            {
                string path = HttpRuntime.AppDomainAppPath + @"logs\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy-MM") + lx + "\\";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                using (StreamWriter writer = new StreamWriter(path + DateTime.Now.ToString("yyyy-MM-dd") + ".log", true, System.Text.Encoding.Default, 0x400))
                {
                    writer.WriteLine(DateTime.Now.ToString() + "  ---  " + v_Msg);
                    writer.Flush();
                    writer.Close();
                    writer.Dispose();
                }
            }
            catch (Exception ex)
            {
                
            }
        }

这个是在webservice中记录日志的方法,偶尔会报The process cannot access the file 路径 because it is being used by another process的错误,不知道是哪里的问题,急求解决
异常

------解决方案--------------------
是不是什么地方漏关闭了