title: logging exception in c#
body: <p><strong>logging exception</strong> 
   the code below allows to save the content of an exception in a text file. Here I'm getting only the decription of the error.</p>
  
  <p><strong>but it is not  telling me where the exception occured, at which line.</strong>
  Can anyone tell me how can I achive that so I can get even the line number where the exception occured?</p>
  
  <pre><code>#region WriteLogError
  /// &lt;summary&gt;
  /// Write an error Log in File
  /// &lt;/summary&gt;
  /// &lt;param name="errorMessage"&gt;&lt;/param&gt;
  public void WriteLogError(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)
    {
      WriteLogError(ex.Message);
    }
  
  }
  
  #endregion
  </code></pre>