How does a C # write text file write a carriage return line feed?

Source: Internet
Author: User
public void Writelogfile (String input)
{
Specify the directory for the log file
String fname = "C:\\inetpub\\wwwroot\\commonfunction\\upfile" + "\\logfile.txt";
Defining a File Information object
FileInfo finfo = new FileInfo (fname);

Determine if a file exists and is greater than 2K
if (finfo. Exists && Finfo. Length > 2048)
{
Delete the file
Finfo. Delete ();
}
Create a write-only file stream
using (FileStream fs = Finfo. Openwrite ())
{
Create a write stream based on the file flow created above
StreamWriter w = new StreamWriter (FS);
Sets the starting position of the write data stream to the end of the file stream
W.basestream.seek (0, Seekorigin.end);
Write "Log Entry:"
W.write ("\nlog Entry:");
Writes the current system time and wraps the line
W.write ("{0} {1} \ r \ n", DateTime.Now.ToLongTimeString (),
DateTime.Now.ToLongDateString ());
Write the contents of the log and wrap the line
W.write (input + "\ n");
Write to------------------------------------"and wrap the line
W.write ("------------------------------------\ n");
Clears the contents of the buffer and writes the buffer contents to the underlying stream
W.flush ();
Close Write Data stream
W.close ();
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.