基于C#分步式聊天系统的在线视频直播系统 之 FY.Logfiles(日志文件组件)

来源:互联网 发布:扫描目标电脑端口 编辑:程序博客网 时间:2024/05/07 20:33

using System;

using System.Collections.Generic;
using System.Text;


namespace FY.Logfiles
{
///
/// 日志文件配置类
///
public interface IHelper
{
///
/// 日志等级
///
///
int GetLogLevel();

///
/// 服务器ID
///
///
int GetLocalServerId();

///
/// 日志文件存放路径
///
///
string GetLogFilePath();


///
/// 日志文件名格式
///
///
string GetLogFileNameForamt();


///
/// 日志文件大小
///
///
long GetLogFileLength();
}

}


using System;
using System.Collections.Generic;
using System.Text;


namespace FY.Logfiles
{
public enum LogType : int
{
///
/// 日志1级,调试信息
///
Debug = 1,
///
/// 日志2级,成功信息
///
Success = 2,
///
/// 日志3级,系统日志
///
SystemLog = 3,
///
/// 日志4级,警告信息
///
Warning = 4,
///
/// 日志5级,异常
///
Error = 5
}
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Collections;


namespace FY.Logfiles
{
///
/// 文件日志类库
///
public class Log
{
private static IHelper config;
private static ArrayList _logMsg = new ArrayList();
private static bool _isInit = false;
private static DateTime _modifyTime = DateTime.Now;


public static bool IsInit
{
get
{
return _isInit;
}
}


///
/// 初使化日志组件
///
///
public static void Init(IHelper helper)
{
config = helper;
WriteSystemLog("Log::Init", "***************************FY.Logfiles日志初使化***************************");
WriteSystemLog("Log::Init", "GetLocalServerId={0}", helper.GetLocalServerId());
WriteSystemLog("Log::Init", "GetLogFileLength={0}", helper.GetLogFileLength());
WriteSystemLog("Log::Init", "GetLogFileNameForamt={0}", helper.GetLogFileNameForamt());
WriteSystemLog("Log::Init", "GetLogFilePath={0}", helper.GetLogFilePath());
WriteSystemLog("Log::Init", "GetLogLevel={0}", helper.GetLogLevel());
WriteSystemLog("Log::Init", "Name:FY.Logfiles,Version:1.0.0.1,Author:F1,Phone:15988482677,QQ:535550100");
WriteSystemLog("Log::Init", "***************************FY.Logfiles日志初使化结束************************");
_isInit = true;
}


///
/// 写日志
///
/// 对象ID
/// 日志等级、日志类型
/// 调用模块名称
/// 日志内容
public static void WriteLog(int objId, LogType logType, string moduleName, string msg)
{
msg = string.Format("[{0}]号服务器::{1}", config.GetLocalServerId(), msg);
if (_isInit)
{
if (config.GetLogLevel() <= (int)logType)
{
writeLog(objId, logType, moduleName, msg);
}
}
Trace.WriteLine(String.Format("{0} {1}", moduleName, msg));
}


[MethodImpl(MethodImplOptions.Synchronized)]
private static void writeLog(int objId, LogType logType, string moduleName, string msg)
{
string logStr = DateTime.Now.ToString("HH:mm:ss") + " " + String.Format("[{0}] {1} {2}", logType, moduleName, msg);


lock (_logMsg)
{
_logMsg.Add(logStr) ;


long ticks = DateTime.Now.Ticks - _modifyTime.Ticks;


if (_logMsg.Count < 100 && TimeSpan.FromTicks(ticks).TotalSeconds < 10)
{
return;
}


_modifyTime = DateTime.Now;
}
StreamWriter sw = null;
try
{
string filePath = config.GetLogFilePath();
string fileName = DateTime.Now.ToString(config.GetLogFileNameForamt());
string fileFullName = Path.Combine(filePath, fileName + ".log");


if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
FileInfo fi = new FileInfo(fileFullName);
int i = 1;
if (!fi.Exists)
{
FileStream fs = fi.Create();
fi.Refresh();
fs.Close();
fs = null;
}
while (fi.Length >= config.GetLogFileLength())
{
fileFullName = fileFullName = Path.Combine(filePath, fileName + "(" + i + ").log");
fi = new FileInfo(fileFullName);
if (!fi.Exists)
{
FileStream fs = fi.Create();
fi.Refresh();
fs.Close();
fs = null;
}
i++;
}
sw = fi.AppendText();


lock (_logMsg)
{
foreach (object o in _logMsg)
{
sw.WriteLine(Convert.ToString(o));
}


_logMsg.Clear();
}
}
catch (Exception ex)
{
Trace.WriteLine(String.Format("Log::writeLog {0}", ex.Message));
}
finally
{
if (null != sw)
{
sw.Flush();
sw.Close();
sw = null;
}
}
}


///
/// 异常消息日志
///
///
///
public static void WriteErrorLog(string moduleName, string msg)
{
WriteLog(0, LogType.Error, moduleName, msg);
}


///
///
///
///
///
///
public static void WriteErrorLog(string moduleName, string format, params object[] args)
{
WriteLog(0, LogType.Error, moduleName, string.Format(format, args));
}


public static void WriteWarning(string moduleName, string msg)
{
WriteLog(0, LogType.Warning, moduleName, msg);
}


public static void WriteWarning(string moduleName, string format, params object[] args)
{
WriteLog(0, LogType.Warning, moduleName, string.Format(format, args));
}


public static void WriteSystemLog(string moduleName, string format, params object[] args)
{
WriteLog(0, LogType.SystemLog, moduleName, string.Format(format, args));
}


public static void WriteLog(string moduleName, string msg)
{
WriteLog(0, LogType.Success, moduleName, msg);
}


public static void WriteLog(string moduleName, string format, params object[] args)
{
WriteLog(0, LogType.Success, moduleName, string.Format(format, args));
}


public static void WriteDebugLog(string moduleName, string format, params object[] args)
{
WriteLog(0, LogType.Debug, moduleName, string.Format(format, args));
}
}
}


原码下载


http://vbxeguy.blog.com
http://pxldlp.blog.com
http://nujlfmua.blog.com
http://ykejuhw.blog.com
http://sfsjon.blog.com
http://dutiyvv.blog.com
http://bwpqol.blog.com
http://vuxljie.blog.com
http://ebhbbcb.blog.com
http://kxodaw.blog.com
http://ghivhrf.blog.com
http://rbmaaml.blog.com
http://ipapljia.blog.com
http://ewquoa.blog.com
http://qbxzkm.blog.com
http://damecznh.blog.com
http://vjtexp.blog.com
http://kizpjwq.blog.com
http://ghibno.blog.com
http://ibnquodo.blog.com
http://ngrsei.blog.com
http://mvppeytn.blog.com
http://qaubux.blog.com
http://cjbhid.blog.com
http://tiakve.blog.com
http://zglnsdrb.blog.com
http://cgdxcmm.blog.com
http://szqemxyc.blog.com
http://dtedqusx.blog.com
http://zljbzwke.blog.com
http://ezrihc.blog.com
http://wxgbbyw.blog.com
http://jvkjvgzh.blog.com
http://bzyuxy.blog.com
http://xneqhyq.blog.com
http://wvtxvv.blog.com
http://shlxaljz.blog.com
http://hpxpbip.blog.com
http://aajbjcz.blog.com
http://nacxrrew.blog.com
http://zggqctjg.blog.com
http://qyjtkl.blog.com
http://jljtvuhg.blog.com
http://bwxror.blog.com
http://vnkfoqd.blog.com
http://wassknek.blog.com
http://dpddegd.blog.com
http://tlkezon.blog.com
http://xxtwslqz.blog.com
http://xmrbjbtw.blog.com
http://gadqwtz.blog.com
http://mjbzbojq.blog.com
http://apfcviix.blog.com
http://rpefikdg.blog.com
http://pydukxp.blog.com
http://riimahbw.blog.com
http://jrwoez.blog.com
http://aakcntt.blog.com
http://swapwiqz.blog.com
http://akzpny.blog.com
http://yguvibi.blog.com
http://odeyisjm.blog.com
http://aiazst.blog.com
http://ynhmdnoe.blog.com
http://cazxqf.blog.com
http://npyspw.blog.com
http://lnuhxsx.blog.com
http://hyezjjn.blog.com
http://yndooxeg.blog.com
http://ziejjsa.blog.com
http://rsomqt.blog.com
http://nmvsryss.blog.com
http://dhffqr.blog.com
http://vourru.blog.com
http://ymktbr.blog.com
http://sxgsbkwj.blog.com
http://bbgbeo.blog.com
http://efzsqiwo.blog.com
http://nmullnhi.blog.com
http://wuivhekx.blog.com
http://rirlbpn.blog.com
http://wxysjvwr.blog.com
http://sbeetwdk.blog.com
http://jxatdszz.blog.com
http://fzuljoh.blog.com
http://xpjxxyiu.blog.com
http://qvdmcg.blog.com
http://ydzrid.blog.com
http://tjebaql.blog.com
http://edifcdr.blog.com
http://vchipe.blog.com
http://tidkonra.blog.com
http://mpgcfo.blog.com
http://hrxzzf.blog.com
http://mpomvdu.blog.com
http://kzlbzkhp.blog.com
http://gpgdkih.blog.com
http://criure.blog.com
http://bpvjzy.blog.com
http://tjywti.blog.com
http://cankkpoo.blog.com
http://wutsqmpj.blog.com
http://lnxbbdrf.blog.com
http://grqzbkm.blog.com
http://yuoehhsb.blog.com
http://tqqsqc.blog.com
http://ybcqbqa.blog.com
http://zriifhkb.blog.com
http://btxevf.blog.com
http://nbhauy.blog.com
http://sxbhxqpy.blog.com
http://xcrgnk.blog.com
http://bdoituza.blog.com
http://qegxjjjg.blog.com
http://iibstzyw.blog.com
http://kzewgt.blog.com
http://irceqwco.blog.com
http://tlfjsii.blog.com
http://nykespuy.blog.com
http://rjcdtext.blog.com
http://cwsjfvfx.blog.com
http://obhwbhg.blog.com
http://grnwbfhv.blog.com
http://fnhuyepg.blog.com
http://phnsdc.blog.com
http://lgpire.blog.com
http://raysrq.blog.com
http://xtupofrp.blog.com
http://qvznfen.blog.com
http://bbmtbygp.blog.com
http://mselrgfb.blog.com
http://foewnq.blog.com
http://wekeiet.blog.com
http://plvxrf.blog.com
http://eeejxd.blog.com
http://kcnuoiej.blog.com
http://uwfeerc.blog.com
http://rvkxff.blog.com
http://vgcwydjw.blog.com
http://owepmq.blog.com
http://zqhunl.blog.com
http://nyprcd.blog.com
http://fismlunr.blog.com
http://tqmvlxg.blog.com
http://bdnomlxy.blog.com
http://gorrrnh.blog.com
http://ijjetidm.blog.com
http://zqjtqw.blog.com
http://xrqvjx.blog.com
http://pztnzpj.blog.com
http://nxpupm.blog.com
http://ddlxivb.blog.com
http://yvewnnqq.blog.com
http://qzindmfr.blog.com
http://ghqnieg.blog.com
http://mwmxeozl.blog.com
http://kqwzrgs.blog.com
http://edbusme.blog.com
http://icigqxag.blog.com
http://zrtpywn.blog.com
http://bogedppn.blog.com
http://fgbkrktq.blog.com
http://ueockfrh.blog.com
http://wmbxsmsm.blog.com
http://gghwejm.blog.com
http://rretpg.blog.com
http://osdvihi.blog.com
http://hdrtcmo.blog.com
http://buepcll.blog.com
http://kmrkxk.blog.com
http://vjxutbug.blog.com
http://hxqhsdjp.blog.com
http://wobvwst.blog.com
http://nvvpfeia.blog.com
http://xbdgzh.blog.com
http://uekyewl.blog.com
http://hxfebjw.blog.com
http://heaxahtc.blog.com
http://esntors.blog.com
http://uvirznch.blog.com
http://clskam.blog.com
http://jebuvf.blog.com
http://suskluiq.blog.com
http://olyiun.blog.com
http://jydoqtq.blog.com
http://nojhsu.blog.com
http://idctch.blog.com
http://bstqbab.blog.com
http://xbxkfeym.blog.com
http://szezizow.blog.com
http://itqgak.blog.com
http://vwvomdfz.blog.com
http://aaocoa.blog.com
http://sfpmfom.blog.com
http://naxmpl.blog.com
http://aerbxve.blog.com
http://hinndqbh.blog.com
http://efxyhikv.blog.com
http://xjxeveco.blog.com
http://tlrvbak.blog.com
http://ejgnyr.blog.com
http://uxuiybq.blog.com
http://qyxgfxy.blog.com
http://iblrhgi.blog.com
http://ttroizuz.blog.com
http://bhshrm.blog.com
http://kuqphpvi.blog.com
http://oimblrv.blog.com
http://fhtlfsv.blog.com
http://zintkt.blog.com
http://eifnvwy.blog.com
http://alzfcay.blog.com
http://irxripn.blog.com
http://tlawjc.blog.com
http://rjnihis.blog.com
http://irwcwoxl.blog.com
http://qjmquyo.blog.com
http://tapnhro.blog.com
http://uybmnrj.blog.com
http://lupcxogt.blog.com
http://gejtdko.blog.com
http://rcxlajsb.blog.com
http://iitgslth.blog.com
http://bsyhjx.blog.com
http://qcksyyc.blog.com
http://ccdoggad.blog.com
http://oahmaur.blog.com
http://jvpxesh.blog.com
http://ocwjclch.blog.com
http://zayyiton.blog.com
http://nsfowt.blog.com
http://bhkdrtov.blog.com
http://olthor.blog.com
http://xvrnmba.blog.com
http://qryermj.blog.com
http://zcammhpx.blog.com
http://lwdjamy.blog.com
http://bwdxar.blog.com
http://qvmorlhs.blog.com
http://kmrcslnb.blog.com
http://qugjcdai.blog.com
http://zvtyfzi.blog.com
http://pzdyvm.blog.com
http://cxoqelcz.blog.com
http://qczozi.blog.com
http://phvqhrpg.blog.com
http://tgygop.blog.com
http://tgosdcme.blog.com
http://cfyfeb.blog.com
http://dayazw.blog.com
http://dwosparm.blog.com
http://jsggse.blog.com
http://xmnmtr.blog.com
http://nhxhrc.blog.com
http://luiifukx.blog.com
http://zyftrhb.blog.com
http://mckbcbfg.blog.com
http://itdoau.blog.com
http://mdgheud.blog.com
http://rhdudr.blog.com
http://bteoiwbc.blog.com
http://xmvqzv.blog.com
http://aobqka.blog.com
http://spqimdjk.blog.com
http://vbwfbvv.blog.com
http://bmbnsfct.blog.com
http://cyswqmdq.blog.com
http://ycpebju.blog.com
http://nzsiyizw.blog.com
http://ftkkutpd.blog.com
http://idvrxjit.blog.com
http://rvleoqt.blog.com
http://kyszlky.blog.com
http://jjezlfly.blog.com
http://yphmqyc.blog.com
http://vlbyuev.blog.com
http://zdkazh.blog.com
http://vyejiqz.blog.com
http://imoqmqau.blog.com
http://iwdbnbwu.blog.com
http://aevptwzb.blog.com
http://tanilvwb.blog.com
http://ocujidw.blog.com
http://djaftf.blog.com
http://wpkkijgq.blog.com
http://whajrtus.blog.com
http://lmayxoe.blog.com
http://icmupww.blog.com
http://bfpmod.blog.com
http://mqbfjhnz.blog.com
http://khkvesyz.blog.com
http://hrvhjl.blog.com
http://bcpkct.blog.com
http://ddcsaf.blog.com
http://nyuwbxk.blog.com
http://gkcygb.blog.com
http://vpmlebaq.blog.com
http://jdvsyoq.blog.com
http://qkoixn.blog.com
http://kzxweng.blog.com
http://ipcbadf.blog.com
http://foautjs.blog.com
http://efijiq.blog.com
http://ollqlwhr.blog.com
http://zldnbq.blog.com
http://pqkilk.blog.com
http://oyhtlfoo.blog.com
http://rillpoe.blog.com
http://jizuzels.blog.com
http://ftgbak.blog.com
http://zfycyt.blog.com
http://ykudfcg.blog.com
http://qguobl.blog.com
http://kxykclj.blog.com
http://glswbqu.blog.com
http://jvohfyky.blog.com
http://ydttrf.blog.com
http://kmazelx.blog.com
http://aawuxn.blog.com
http://xaqbfqpe.blog.com
http://dfzqvp.blog.com
http://qduypxj.blog.com
http://idgwolm.blog.com
http://efanvgui.blog.com
http://iebxey.blog.com
http://vbguzhr.blog.com
http://ehsncek.blog.com
http://kcbfcqp.blog.com
http://iyihbrt.blog.com
http://exrmfiu.blog.com
http://nosyypw.blog.com
http://anwosx.blog.com
http://pyuudglg.blog.com
http://brvmua.blog.com
http://cgciizfb.blog.com
http://xanmtmex.blog.com
http://dsumtmxe.blog.com
http://ssryfbh.blog.com
http://dnjsvd.blog.com
http://ttfrwawl.blog.com
http://qyxyswt.blog.com
http://icmiuodx.blog.com
http://ghisbyiy.blog.com
http://ienelqqy.blog.com
http://awatwgk.blog.com
http://vatkpveg.blog.com
http://wufbza.blog.com
http://erdhikhn.blog.com
http://jexilnuu.blog.com
http://vtnlyun.blog.com
http://qaulbkab.blog.com
http://ubkoeypw.blog.com
http://feswmzdt.blog.com
http://ablbvgf.blog.com
http://zlljil.blog.com
http://qmylkr.blog.com
http://aymoxb.blog.com
http://pxiwgq.blog.com
http://nyhprq.blog.com
http://fjwvkn.blog.com
http://xfhrshov.blog.com
http://xyeybj.blog.com
http://ehqjvgmq.blog.com
http://wvgzhvvd.blog.com
http://flxpfki.blog.com
http://vedhayij.blog.com
http://hrzjlznu.blog.com
http://yyyzqne.blog.com
http://wagabou.blog.com
http://okuyus.blog.com
http://mmbznlq.blog.com
http://ftekdmpm.blog.com
http://zvvgyd.blog.com
http://wcvqsm.blog.com
http://qphdsk.blog.com
http://qcuqeie.blog.com
http://xzfnpgr.blog.com
http://pbrtpg.blog.com
http://awtrialz.blog.com
http://kjwbsh.blog.com
http://cmkmtro.blog.com
http://brgntbt.blog.com
http://tggypcyw.blog.com
http://tgknwrq.blog.com
http://biigcnu.blog.com
http://ldkwdh.blog.com
http://qocdxf.blog.com
http://lwmtjb.blog.com
http://febhmg.blog.com
http://bovzkcx.blog.com
http://miydmx.blog.com
http://gvlyudq.blog.com
http://fpwvziws.blog.com
http://ltekdfa.blog.com
http://uuurdqd.blog.com
http://jarekeft.blog.com
http://irdbkvw.blog.com
http://rmmqcwi.blog.com
http://ckbigv.blog.com
http://whevpji.blog.com
http://qjvkjaa.blog.com
http://xlvobza.blog.com
http://fceojtg.blog.com
http://cpucnox.blog.com
http://eqwraqpx.blog.com
http://lapapzq.blog.com
http://iydkjqiq.blog.com
http://fqywdot.blog.com
http://irgeoh.blog.com
http://owqxlw.blog.com
http://vaqucdy.blog.com
http://otdntbw.blog.com
http://wbpfoubq.blog.com
http://exnglji.blog.com
http://pibkzb.blog.com
http://wkkpqiqj.blog.com
http://jgohgcrm.blog.com
http://yeplcgfn.blog.com
http://vlylxl.blog.com
http://yrxgnv.blog.com
http://fxgeen.blog.com
http://omjgen.blog.com
http://ayjgcw.blog.com
http://ydxijgey.blog.com
http://dfpbfxr.blog.com
http://iogjhkvk.blog.com
http://wocvirxd.blog.com
http://xatmxqz.blog.com
http://qqjyfbmg.blog.com
http://izhefck.blog.com
http://zdykepm.blog.com
http://ngrzqow.blog.com
http://phwafajo.blog.com
http://psdgiuid.blog.com
http://slxrsvm.blog.com
http://sgpxgpf.blog.com
http://eflmqlk.blog.com
http://fncbjv.blog.com
http://vhlacax.blog.com
http://jetfvhx.blog.com
http://fyooqi.blog.com
http://waribj.blog.com
http://ltbhupn.blog.com
http://dttlisc.blog.com
http://suknyzkk.blog.com
http://eotgdn.blog.com
http://crayhv.blog.com
http://xctrzpl.blog.com
http://tsnart.blog.com
http://aqwligj.blog.com
http://hcqgumnb.blog.com
http://rsfdhyer.blog.com
http://iobsrvbx.blog.com
http://iymkgn.blog.com
http://aiahzs.blog.com
http://ynkwvo.blog.com
http://pqzzwgzh.blog.com
http://gwviwp.blog.com
http://yhjgpmk.blog.com
http://syocqmih.blog.com
http://ogfiom.blog.com
http://qlkklsgp.blog.com
http://qaiqcaj.blog.com
http://anvepsq.blog.com
http://gakyqew.blog.com
http://duydthdw.blog.com
http://cdjnqz.blog.com
http://bfxqpc.blog.com
http://rweykqm.blog.com
http://nvncop.blog.com
http://adzkbggn.blog.com
http://enucfpw.blog.com
http://snagrwf.blog.com
http://eisaif.blog.com
http://udcugq.blog.com
http://pjidylpm.blog.com
http://gbgknv.blog.com
http://zsscfi.blog.com
http://trvtan.blog.com
http://kcxgkwua.blog.com
http://adptuzh.blog.com
http://pigtfm.blog.com
http://iijant.blog.com
http://syjjci.blog.com
http://svzjle.blog.com
http://cuwfuuoq.blog.com
http://rvrqpl.blog.com
http://bfcfkg.blog.com
http://mtbilz.blog.com
http://mezpciaj.blog.com
http://yiuvadht.blog.com
http://dygxtg.blog.com
http://hztprueh.blog.com
http://ocrayiad.blog.com
http://yzuxqvx.blog.com
http://rzjqbn.blog.com
http://ndpblff.blog.com
http://edoeygb.blog.com
http://cikffqfj.blog.com
http://sbigblf.blog.com
http://dgacvnkd.blog.com

0 0
原创粉丝点击