Error Log

public class clsError

{

    //Variable used to store error

    string strErr;

    

    #region "Constructor Initialized"

    public clsError(string strError)

{

        TextWriter sw;

        string strUserId=string.Empty;

        strErr = strError;

        string Filename;

        try

        {

            Filename = HttpContext.Current.Server.MapPath(@"..\Errorlogs\") + "Errorlog- " + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".txt";            

        }

        catch (Exception ex)

        {

            Filename = HttpContext.Current.Server.MapPath(@"Errorlogs\") + "Errorlog- " + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".txt";           

        }

        try{

            //Locking the error in error log            

            sw = File.AppendText(Filename);

            sw.WriteLine("------------------------------------------------------------------");

            sw.WriteLine("Errorlog Time -> " + DateTime.Now.ToString());

            sw.WriteLine("UserID -> " + strUserId);

            sw.WriteLine(" ");

            sw.WriteLine(strError);

            sw.WriteLine("------------------------------------------------------------------");

            sw.Flush();

            sw.Close();

            }

        catch(Exception er)

            {

                HttpContext.Current.Response.Write("ERROR : "+er.ToString());

            }       

}

    #endregion

}

//Code file

try

{

}

catch (Exception ex)

        {

            clsError objError = new clsError(ex.ToString());

            objError = null;

            throw ex;

        }