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 {}
}
}