How to Create log file using C#

Hi friends,
Here is the C# function used in the creation of the Log files. You can use this Code to maintain the Error Log file into your project .
Here is the method,

 public void CreateLogFile(String logMsg)
    {
        FileStream lofFile;
        lofFile = new FileStream("BackUpLogFile" + DateTime.Today.ToString("ddMMyyyy") + ".txt", FileMode.Append); //this will add the Date time details in the log file
        TextWriter txtWriter = new StreamWriter(lofFile);//write the containts
        txtWriter .WriteLine("Log:" + DateTime.Now + ":- " + logMsg);
        txtWriter .Close();
    }

Hope this will help you ...
Regards
Rajesh

0 comments: