Write your own log, the method of deleting the log on a regular basis.
The method is relatively simple, record it.
<summary>///write Log///</summary>//<param name= "STRMSG" > Content </param> <param name= "strpath" > Path (Folder path relative to hycom) </param>//<param name= "FileName" > Log name (Default yyyy-mm- Dd.txt) </param> public static void Writelog (String strmsg,string strpath,string fileName) { String path = AppDomain.CurrentDomain.BaseDirectory + strpath; if (!path. EndsWith ("\ \") | |! Path. EndsWith ("/")) {path+= "\ \"; } if (! Directory.Exists (Path)) {directory.createdirectory (path); } deletelog (path); if (filename== "") {FileName = DateTime.Now.ToString ("yyyy-mm-dd") + ". txt"; } if (!filename.endswith (". txt")) {filename+= ". txt"; } try {//string fileName =datetime.now.tostring ("yyyy-mm-dD ") +". txt "; StreamWriter SW = File.appendtext (path+filename); Sw. WriteLine ("{0}:{1}", DateTime.Now.ToString ("Yyyy-mm-dd HH:mm:ss:fff"), STRMSG); Sw. WriteLine ("\n\r"); Sw. Flush (); Sw. Close (); } catch {}}///<summary>//write Log///</summary>//<param Name= "STRMSG" > Content </param>//<param name= "strpath" > Path (Folder path relative to hycom) </param> public s tatic void Writelog (String strmsg,string strpath) {string fileName = DateTime.Now.ToString ("Yyyy-mm-dd" ) + ". txt"; Writelog (Strmsg,strpath,filename); }///<summary>///Regular Delete log///</summary>//<param name= "strpath" > Log path < /param> private static void Deletelog (String strpath) {if (Directory.Exists (Strpat h)) {DirectoryInfoDinfor = new DirectoryInfo (strpath); fileinfo[] files = dinfor. GetFiles (); foreach (FileInfo file in files) {try {//delete create The log date is 3 months before the log if (Datetime.compare (file. Creationtime.addmonths (3), DateTime.Now) <0) {file. Delete (); }//delete the last modified log date is 3 months before the log if (Datetime.compare (file. Lastwritetime.addmonths (3), DateTime.Now) <0) {file. Delete (); }//delete log name date is 3 months before the log if (Datetime.compare (convert.todatetime (file. Name.substring (0,10)), DateTime.Now.AddMonths ( -3)) <0) {file. Delete (); }} catch (Exception ex) { Continue } } } }
Simple Log Management Code