91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

log4net,可以根據配置的時間長度,實現了自動刪除過期的日志文件,歡迎大家使用或者分享更科學的方法。

資源截圖

代碼片段和文件信息

using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?log4net.Config;
using?log4net;
using?log4net.Appender;
using?System.IO;
using?System.xml;
using?System.Threading;

namespace?CSCC.Net.Common
{
????public?class?Log
????{
????????private?static?log4net.ILog?_log?=?null;
????????///?
????????///?日志文件過期時間(單位:天),默認半年=180天
????????///?

????????private?static?int?outdate_days?=?180;

????????private?static?object?lockHelper?=?new?object();
????????private?static?log4net.ILog?InnerLog
????????{
????????????get
????????????{
????????????????if?(null?==?_log)
????????????????{
????????????????????lock?(lockHelper)
????????????????????{
????????????????????????if?(null?==?_log)
????????????????????????{
????????????????????????????try
????????????????????????????{
????????????????????????????????string?cfgfile?=?“log4net.config“;//當前(exe文件所在)目錄
????????????????????????????????xmlConfigurator.Configure(new?System.IO.FileInfo(cfgfile));
????????????????????????????????_log?=?LogManager.GetLogger(“Logging“);

????????????????????????????????#region?刪除過期的日期文件
????????????????????????????????Thread?th?=?new?Thread(()?=>
????????????????????????????????{
????????????????????????????????????try
????????????????????????????????????{
????????????????????????????????????????DeleteOutdatefiles(_log?cfgfile);
????????????????????????????????????}
????????????????????????????????????catch?(Exception?ex)
????????????????????????????????????{
????????????????????????????????????}
????????????????????????????????});
????????????????????????????????th.IsBackground?=?true;
????????????????????????????????th.Start();
????????????????????????????????#endregion
????????????????????????????}
????????????????????????????catch?(Exception?ex)
????????????????????????????{
????????????????????????????}
????????????????????????}
????????????????????}
????????????????}
????????????????return?_log;
????????????}
????????}
????????///?
????????///?刪除過期的日志文件
????????///?

????????private?static?void?DeleteOutdatefiles(ILog?logstring?cfgfile)
????????{
????????????if?(log?==?null?||
????????????????!log.IsInfoEnabled?||?
????????????????!log.IsErrorEnabled)
????????????{
????????????????return;
????????????}

????????????try
????????????{
????????????????xmlDocument?xdoc?=?new?xmlDocument();
????????????????xdoc.Load(cfgfile);
????????????????var?node?=?xdoc.SelectSingleNode(“log4net“);
????????????????//附帶屬性到log4net.config,只能在根節點設置添加。
????????????????//這個附帶屬性設置還不能放到其它節點,放到其它節點log4net解析會報錯(雖未影響結果,但看著不舒服)
????????????????if?(null?!=?node?||?node.Attributes?!=?null?||?node.Attributes.Count?>?0)
????????????????{
????????????????????outdate_days?=?int.Parse(node.Attributes[“outdate_days“].Value);
????????????????}
????????????}
????????????catch?(Exception?exx)
????????????{
????????????}
????????????var?apps?=?log.Logger.Re

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-10-23?09:09??log4net.test\
?????目錄???????????0??2017-10-29?10:43??log4net.test\bin\
?????目錄???????????0??2017-10-27?10:22??log4net.test\bin\Debug\
?????目錄???????????0??2017-10-29?10:24??log4net.test\bin\Debug\log\
?????文件?????????647??2017-10-29?10:27??log4net.test\bin\Debug\log4net.config
?????文件??????266240??2017-10-23?09:07??log4net.test\bin\Debug\log4net.dll
?????文件???????10240??2017-10-29?10:43??log4net.test\bin\Debug\log4net.test.exe
?????文件???????30208??2017-10-29?10:43??log4net.test\bin\Debug\log4net.test.pdb
?????文件???????11600??2017-10-25?10:19??log4net.test\bin\Debug\log4net.test.vshost.exe
?????文件??????????70??2017-10-29?10:24??log4net.test\bin\Debug\log\log.txt
?????文件?????????140??2017-10-25?10:19??log4net.test\bin\Debug\log\log.txt2017-10-25.txt
?????文件?????????210??2017-10-26?10:13??log4net.test\bin\Debug\log\log.txt2017-10-26.txt
?????文件?????????353??2017-10-27?10:23??log4net.test\bin\Debug\log\log.txt2017-10-27.txt
?????文件??????????71??2017-10-28?10:23??log4net.test\bin\Debug\log\log.txt2017-10-28.txt
?????文件???????10964??2017-10-29?10:40??log4net.test\CsccLog.cs
?????文件?????????647??2017-10-29?10:27??log4net.test\log4net.config
?????文件??????266240??2017-10-23?09:07??log4net.test\log4net.dll
?????文件????????2906??2017-10-23?09:13??log4net.test\log4net.test.csproj
?????文件?????????865??2017-10-23?09:06??log4net.test\log4net.test.sln
?????文件???????24064??2017-10-29?10:43??log4net.test\log4net.test.suo
?????目錄???????????0??2017-10-23?09:06??log4net.test\obj\
?????目錄???????????0??2017-10-23?09:06??log4net.test\obj\x86\
?????目錄???????????0??2017-10-29?10:43??log4net.test\obj\x86\Debug\
?????文件????????5891??2017-10-29?10:43??log4net.test\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件?????????445??2017-10-27?10:22??log4net.test\obj\x86\Debug\log4net.test.csproj.FileListAbsolute.txt
?????文件???????10240??2017-10-29?10:43??log4net.test\obj\x86\Debug\log4net.test.exe
?????文件???????30208??2017-10-29?10:43??log4net.test\obj\x86\Debug\log4net.test.pdb
?????目錄???????????0??2017-10-23?09:06??log4net.test\obj\x86\Debug\TempPE\
?????文件?????????394??2017-10-29?10:43??log4net.test\Program.cs
?????目錄???????????0??2017-10-23?09:06??log4net.test\Properties\
?????文件????????1356??2017-10-23?09:06??log4net.test\Properties\AssemblyInfo.cs
............此處省略0個文件信息

評論

共有 條評論