Custom Logger file

Following is the code for a custom logger file to be used in c# programs/applications.
 Just create a class file named Logger.cs and add following code to it,
 
  1. public class Logger  
  2.   {  
  3.       #region Public member methods.  
  4.       /// <summary>  
  5.       /// Writes detailed log to a error log text file.  
  6.       /// </summary>  
  7.       /// <param name="exception"></param>  
  8.       public static void Write(Exception exception)  
  9.       {  

  10.           var logFile = String.Concat(AppDomain.CurrentDomain.BaseDirectory, "ErrorLog.txt");  
  11.   
  12.           
  13.               var logWriter = File.AppendText(logFile);  
  14.               logWriter.WriteLine("=>" + DateTime.Now + " " + " An Error occured : " + exception.StackTrace + " Message : " + exception.Message + "\n\n");  
  15.               logWriter.Close();  
  16.                      
  17.       }   
  18.       #endregion  
  19.   }  
Usage of the code,
 
  1. try{  
  2. //Some Exception  
  3. }  
  4. catch(Exception exception)  
  5. {  
  6. Logger.Write(exception)  
  7. }  
Check the generated logger file in your base directory or in bin folder.