UnlareeAddirev9
New Member
My team is working on a C# ASP.NET Web application.I decided to handle errors by writing to an error log file.The log.Error method that I wrote would log to a physical log file in an error directory.I thought it would be appropriate to use a lock in order to control threads when it comes to executing the log.Error method because I want to log the error every time it occurs.Therefore here is the format for most of my exception handling:\[code\]protected void blahblahCsharpMethodBlahBlah(){try{ blah blah C# code blah blah}catch(Exception ex ){ lock (_objectblahblahCsharpMethodBlahBlah) { // The following log.Error method that I wrote would log to a physical log file in an error directory. log.Error(ex.ToString(), PerlsPivotErrorDirectory, System.Reflection.MethodBase.GetCurrentMethod().Name, this.GetType().Name, System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location));}}} // protected void blahblahCsharpMethodBlahBlah()\[/code\]Is it proper practice to use a lock in order to control threads so that they execute the log.Error method in a proper serialized manner?