Hi,
the below code getting error "system.io.ioexception the process cannot access the file because it is being used by another process". please can any suggest, how to handle this exception.
string path = context.Current.Server.MapPath("~/UserLogging/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + DateTime.Today.ToString("dd-MMM-yy") + ".log";
if (!File.Exists(path))
{
File.Create(path).Dispose();
}
using (StreamWriter writer = File.AppendText(path))
{
string error = "\r\nLog written at : " + DateTime.Now + " Method : " + userFriendlyError ;
writer.WriteLine(error);
writer.WriteLine("==========================================");
writer.Flush();
writer.Close();
}