• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            牽著老婆滿街逛

            嚴(yán)以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            從CodeProject那里找到并且剝離出來的一個Trace Log類

            這個類還不錯的說,希望看到原文的請到CodeProject去看,原文地址是:
            http://www.codeproject.com/debug/logtrace.asp

            下面我把源代碼放上來.
            ////////////////////////////////////////////////////////////////////////
            //??LogTrace.cpp?--?Interface?for?the?CLogTrace?class
            //??A?class?to?do?debug?logging


            #ifndef?__LOGTRACE_H__
            #define?__LOGTRACE_H__

            class?CLogTrace
            {
            //?Construction/Destruction
            public:
            ????CLogTrace();
            ????
            ~CLogTrace();


            //?Attributes
            public:
            ????CString?m_strAppName;

            protected:
            ????BOOL?m_bActive;
            ????CString?m_strFileName;
            ????BOOL?m_bTimeStamp;

            //?Operations
            public:
            ????
            void?WriteLine(LPCTSTR?szLine);
            ????
            void?WriteLine(LPCTSTR?szFormat,?LPCTSTR?szAddInfo);
            ????
            void?WriteLine(LPCTSTR?szFormat,?int?nAddInfo);
            ????
            void?ResetFile();
            ????
            void?OnStartup(BOOL?bActive,?BOOL?bTimeStamp);
            ????
            void?SetFileName(LPCTSTR?szFileName);


            protected:



            //?Inlines
            public:
            ????inline?
            void?SetActive(BOOL?bSet)
            ????
            {
            ????????m_bActive?
            =?bSet;
            ????}

            ????inline?CString?GetFileName()
            ????
            {
            ????????
            return?m_strFileName;
            ????}

            }
            ;


            #endif?//?__LOGTRACE_H__

            ?

            ?

            ////////////////////////////////////////////////////////////////////////
            //??LogTrace.cpp?--?Implementation?of?the?CLogTrace?class


            #include?
            "stdafx.h"
            #include?
            <afxdisp.h>
            #include?
            "LogTrace.h"

            /**************************************************

            ?How?to?use?CLogTrace

            ????1.??Make?a?static?CLogTrace?object?as?a?member?of?the?application?class

            ????2.????Add?the?following?lines?to?the?InitInstance?of?the?program

            ????
            ????m_LogTrace.m_strAppName?=?"MyApp";?//?use?appropriate?name?here

            ????m_LogTrace.SetFileName("Log.txt");?//?sets?the?log?file?name?and?puts?it?in?the?exe?path

            ????m_LogTrace.OnStartup(TRUE,?TRUE);?//?activates?the?log?trace

            ????3.??Also?in?InitInstance,?add?the?following?line?if?you?want?to?empty?the?log?file
            ????each?time?the?application?starts
            ????
            ????m_LogTrace.ResetFile();


            ????4.??Any?time?you?want?to?write?to?the?log?file,?use?the?CLogTrace::WriteLine?functions
            ????these?will?write?the?text?along?with?date?and?time


            ******************************************************
            */




            //////////////////////////////////////////////////////
            //??Construction/Destruction

            CLogTrace::CLogTrace()
            {
            ????m_bActive?
            =?FALSE;
            ????m_bTimeStamp?
            =?TRUE;

            ????CString?s;
            }



            CLogTrace::
            ~CLogTrace()
            {


            }


            ////////////////////////////////////////////////////////
            //??CLogTrace?operations


            void?CLogTrace::ResetFile()
            {
            ????CStdioFile?f;
            ????CFileException?fe;
            ????CString?s;

            ????
            if?(m_strFileName.IsEmpty())?return;

            ????
            if?(f.Open(m_strFileName,?CFile::modeWrite?|?CFile::modeCreate,?&fe)?==?FALSE)
            ????
            {
            ????????
            return;
            ????}


            ????f.Close();
            }




            //?bActive?tells?us?if?we?want?the?trace?to?be?active?or?not
            //?bTimeStamp?tells?us?if?we?want?time?stamps?on?each?line
            //?eliminating?the?time?stamp?allows?us?to?use?this?class?for?a?regular?log?file
            void?CLogTrace::OnStartup(BOOL?bActive,?BOOL?bTimeStamp)
            {
            ????m_bActive?
            =?bActive;
            ????m_bTimeStamp?
            =?bTimeStamp;
            ????
            if?(bTimeStamp?==?FALSE)?return;
            ????CString?s;

            ????
            //?these?***'s?help?to?indicate?when?one?ru?of?the?program?ends?and?another?starts
            ????
            //?because?we?don't?always?overwrite?the?file?each?time

            ????WriteLine(
            "\n\n******************************************\n\n");
            ????s.Format(
            "%s?Log?Trace?%s\n\n",?m_strAppName,?COleDateTime::GetCurrentTime().Format());
            ????WriteLine(s);
            }




            //?function?to?write?a?line?of?text?to?the?log?file
            void?CLogTrace::WriteLine(LPCTSTR?szLine)
            {
            ????CStdioFile?f;
            ????CFileException?fe;
            ????CString?s;

            ????
            if?(m_bActive?==?FALSE)?return;
            ????
            if?(m_strFileName.IsEmpty())?return;

            ????
            if?(f.Open(m_strFileName,?CFile::modeWrite?|?CFile::modeCreate?|
            ????????CFile::modeNoTruncate,?
            &fe)?==?FALSE)
            ????
            {
            ????????
            return;
            ????}


            ????
            try
            ????
            {
            ????????f.SeekToEnd();
            ????????TRACE(
            "LOGGIN?%s\n",?szLine);
            ????????
            if?(m_bTimeStamp)
            ????????
            {
            ????????????s.Format(
            "%s\t%s\n",?COleDateTime::GetCurrentTime().Format(),
            ????????????????szLine);
            ????????}

            ????????
            else
            ????????
            {
            ????????????s.Format(
            "%s\n",?szLine);
            ????????}

            ????????f.WriteString(s);
            ????}

            ????
            catch?(CException*?e)
            ????
            {
            ????????e
            ->Delete();
            ????}

            ????f.Close();
            }


            //?function?to?write?a?line?of?text,?with?an?extra?string
            void?CLogTrace::WriteLine(LPCTSTR?szFormat,?LPCTSTR?szAddInfo)
            {
            ????
            if?(m_bActive?==?FALSE)?return;
            ????CString?s;
            ????s.Format(szFormat,?szAddInfo);
            ????WriteLine(s);
            }



            //?funtion?to?write?a?line?of?text?with?an?extra?integer
            void?CLogTrace::WriteLine(LPCTSTR?szFormat,?int?nAddInfo)
            {
            ????
            if?(m_bActive?==?FALSE)?return;
            ????CString?s;
            ????s.Format(szFormat,?nAddInfo);
            ????WriteLine(s);
            }



            //?function?to?set?the?log?file?name.??don't?pass?a?fill?path!
            //?just?pass?something?like?"log.txt"
            //?the?file?will?be?placed?in?the?same?dir?as?the?exe?file
            void?CLogTrace::SetFileName(LPCTSTR?szFileName)
            {
            ????TCHAR?drive[_MAX_PATH],?dir[_MAX_PATH],?name[_MAX_PATH],?ext[_MAX_PATH];

            ????
            const?char?*path?=?_pgmptr?;

            ????_splitpath(path,?drive,?dir,?name,?ext);

            ????m_strFileName.Format(
            "%s%s%s",?drive,?dir,?szFileName);

            }

            posted on 2006-04-18 10:02 楊粼波 閱讀(2773) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            国产精品久久久久久久久| 亚洲AV无码久久寂寞少妇| 日本道色综合久久影院| 丰满少妇高潮惨叫久久久| 国产三级观看久久| 狠狠色婷婷久久综合频道日韩| 亚洲∧v久久久无码精品| 国产精品激情综合久久| 日本久久久久亚洲中字幕| 国产综合成人久久大片91| 亚洲国产一成人久久精品| 麻豆精品久久精品色综合| 亚洲AⅤ优女AV综合久久久| 99久久超碰中文字幕伊人| 亚洲国产成人精品91久久久 | 亚洲综合伊人久久大杳蕉| 久久成人国产精品二三区| 久久九九兔免费精品6| 伊人色综合久久天天| 中文字幕无码免费久久| 久久青青草原精品国产不卡| 久久国产免费观看精品3| 日本精品久久久久久久久免费| 国产精品久久久久影院色| 伊人久久大香线蕉综合影院首页| 久久国产午夜精品一区二区三区| 国产精品一区二区久久不卡| 久久国产亚洲精品| 精品多毛少妇人妻AV免费久久| 狠狠88综合久久久久综合网| 国产成人久久精品一区二区三区 | 国产成人精品白浆久久69| AV无码久久久久不卡蜜桃| 久久综合亚洲鲁鲁五月天| 亚洲精品久久久www| 天天综合久久一二三区| 亚洲欧洲精品成人久久奇米网| 国产精品美女久久久网AV| 精品99久久aaa一级毛片| 国产成人精品久久| 久久精品国产国产精品四凭|