.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Create Log file

Posted By:Deepika Haridas       Posted Date: October 01, 2010    Points: 15    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This code snippet demonstrates the use to create a log file to store either your error or informational thing
 

This code snippet demonstrates the use to create a log file to store either your error or informational thing like storing executed queries etc.

Here you need to pass the message when you call this function. You can also specify drive in which you want your log files to be stored or else by default it will store in your project's bin folder.

public void writeToLogFile(String s)
{
    String Filename;
    FileStream file;
    file = new FileStream("BackupLog" +DateTime.Today.ToString("yyyyMMdd") + ".txt", FileMode.Append );
    TextWriter tw = new StreamWriter(file);
    tw.WriteLine("Log:" + DateTime.Now + ":- " + s);
    tw.Close();
}




     

Further Readings:

Responses
Author: Deco         Company URL: http://www.dotnetspark.com
Posted Date: October 02, 2010

Storing log in a file is not advisable because when the log file size gets bigger

we have to wait for a long time to open that file.

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend