Error Logging in C# Website

Premsdrielm

New Member
I am planning to implement error logging writing something similar to this:\[code\]public static void WriteError(string errorMessage) { try { string path = "~/Error/" + DateTime.Today.ToString("dd-mm-yy") + ".txt"; if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path))) { File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close(); } using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path))) { w.WriteLine("\r\nLog Entry : "); w.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture)); string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() + ". Error Message:" + errorMessage; w.WriteLine(err); w.WriteLine("__________________________"); w.Flush(); w.Close(); } } catch (Exception ex) { WriteError(ex.Message); } }\[/code\]My question is this: Since it is a website, I will have multiple users simultaneously. In that case, if multiple users encounter exceptions at the same time and try to write to the same file, it will again give me an exception right? In that case, how do I implement error logging correctly for simultaneous users? Or will this work?Thanks in advance.
 
Back
Top