/// <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.