. Net text log passthrough

Source: Internet
Author: User
Tags passthrough

/// <Summary>
/// Write text logs
/// </Summary>
Public void writelog (string message)
{
// Specify the directory of the log file
String filelogpath = appdomain. currentdomain. basedirectory + "// systemlog //";
String filelogname = "SMS _" + datetime. Now. tolongdatestring () + "_log.txt ";
// Define the object of File Information
Fileinfo finfo = new fileinfo (filelogpath + filelogname );

// Create a file-only stream
Using (filestream FS = finfo. openwrite ())
{
// Create a write data stream based on the file stream created above
Streamwriter strwriter = new streamwriter (FS );
// Set the start position of the write data stream to the end of the file stream
Strwriter. basestream. Seek (0, seekorigin. End );
// Write error occurrence time
Strwriter. writeline ("occurrence time:" + datetime. Now. tostring ());
// Write log Content and line feed
Strwriter. writeline ("error content:" + message );
// Write Interval
Strwriter. writeline ("---------------------------------------------");
Strwriter. writeline ();
// Clear the buffer content and write the buffer content to the base stream
Strwriter. Flush ();
// Close the write data stream
Strwriter. Close ();
FS. Close ();
}
}

This method generates a new log file every day to record the log message. The log Content of the day is appended and will not be overwritten.

You can directly input the log Content During the call. You can change the name and path of the log file as needed.

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.