Record error logs on the server

Source: Internet
Author: User

Using system. IO;

Public class debuglog
{
Public debuglog ()
{
//
// Todo: add the constructor logic here
//
}

 

/// <Summary>
/// Create a log based on the main file name of the log
/// </Summary>
/// <Param name = "createtime"> log creation time </param>
/// <Param name = "body"> log Content subject </param>
/// <Param name = "file_prefix"> key subjects of file names </param>
Public static void writelog (datetime createtime, string body, string file_prefix)
{
Try
{
Lock (typeof (debuglog ))
{
String strlogpath = string. empty;
Strlogpath = configurationmanager. deleetpipeline ["logpath"]. tostring ();
If (string. isnullorempty (strlogpath ))
{
Return;
}

// Obtain the log file name of the current day based on the date of the current day.
String strlogfilename = strlogpath + file_prefix + system. datetime. Now. tostring ("yyyy-mm-dd") + ". txt ";
Streamwriter logwriter = NULL;

// Determine whether the log file exists. If the log file exists, continue the row. If the log file does not exist, create and write the title.
If (file. exists (strlogfilename ))
{

Logwriter = file. appendtext (strlogfilename );
}
Else
{
// Create a file
Logwriter = file. createtext (strlogfilename );

}

String strlogcontent = string. empty;
String strlogid = string. empty;
Strlogid = datetime. Now. ticks. tostring ();
Strlogcontent = "------------------------------------------------------------------------" + "\ r \ n ";
Strlogcontent = createtime + "\ t" + "\ r \ n" + body;
Strlogcontent = strlogcontent + "\ r \ n" + "------------------------------------------------------------------------";
Logwriter. writeline (strlogcontent );
Logwriter. Close ();
}
}
Catch {}
}

}

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.