The custom log record function allows you to easily record logs by day.
1. Define the Log Type
Public enum LogType
{
Debug = 0,
Error = 1,
Info = 2,
Warn = 3
}
2. Add static LogHelper class
Public static class LogHelper
{
Public static void Write (string msg, LogType logtype = LogType. Debug)
{
Try
{
String basePath = Path. Combine (AppDomain. CurrentDomain. BaseDirectory, "Logs ");
Directory. CreateDirectory (basePath );
String logPath = Path. Combine (basePath, DateTime. Today. ToString ("yyyyMMdd") + ". log ");
Using (FileStream stream = new FileStream (logPath, FileMode. Append, FileAccess. Write, FileShare. Read ))
{
Using (StreamWriter writer = new StreamWriter (stream, Encoding. UTF8 ))
{
String messge = string. Format ("{0} {1}-OPERATOR: [{2}], Messge: {3 }",
DateTime. Now. ToString (), logtype. ToString (), DeluxeIdentity. Current. User. DisplayName, msg );
Writer. WriteLine (messge );
Writer. Flush ();
}
}
}
Catch (Exception e)
{
Throw new Exception ("log writing Exception:" + e. ToString ());
}
}
}
Iii. Call Methods
LogHelper. Write ("check whether the approval comments on the proposed page are retained abnormally. Cause:" + e. ToString (), LogType. Error );
Iv. Effect