C 按照日期輸出程式日誌

2021-09-02 01:11:59 字數 1654 閱讀 1372

namespace logdata

public static void writelog(logfile logfile, string msg)

catch

}public static void writelog(string msg)

catch

}public static void writelog(string logfile, string msg)

catch}}

public class logmanager

public logmanager(string logpath, string logfileextname, bool writelogtime)

#endregion

#region 屬性

/// /// log 檔案路徑

///

public string logpath

return this.logpath;

}set

else

else

if (!directory.exists(this.logpath))

directory.createdirectory(this.logpath);

}catch

if (!this.logpath.endswith(@"\"))

this.logpath += @"\";}}

}/// /// log 副檔名

///

public string logfileextname

set

}/// /// 是否在每個log行前面新增當前時間

///

public bool writelogtime

set

}/// /// 日誌檔名是否帶日期

///

public bool logfilenameendwithdate

set

}/// /// 日誌檔案的字元編碼

///

public encoding logfileencoding

set

}#endregion

#region 公有方法

public void writelog(string logfile, string msg)

logfilename = string.format(".",

this.logpath,

logfile,

datestring,

this.logfileextname);

using (streamwriter sw = new streamwriter(logfilename, true, logfileencoding))

else}}

catch}}

public void writelog(logfile logfile, string msg)

public void writelog(string msg)

#endregion

}public enum logfile

}

使用時直接呼叫公用方法writelog,裡面設定了錯誤型別.

每天的日誌檔案輸出成乙個資料夾,方便查閱

**:c#中的一種按日期分資料夾的日誌寫法

將tomcat的輸出日誌按照日期分割

1 找到 touch catalina out 將其注釋掉。touch catalina out 2 在注釋掉的這一行的往下大概13行左右的樣子,找到 org.apache.catalina.startup.bootstrap start catalina out 2 1 替換成 org.apach...

scrapy按照時間輸出日誌

1 在settings檔案中設定import datetime to day datetime.datetime.now log file path log資料夾的絕對路徑 log log format to day.year,to day.month,to day.day log level de...

uWSGI日誌按照日期自動切割

touch logreopen root hello touchforlogrotat注 uwsgi.ini 新增配置選項 日誌檔案 aemonize root hello uwsgi.log 生成乙個監聽的檔案,touch touchforlogrotat 相當於修改了建立時間,系統會重新relo...