2012-03-12 40 views
2

我有一個cpp項目,一個cpp cli項目和一個c#win窗體項目。 我在我的CPP本地項目中使用pantheios日誌庫。當我嘗試寫日誌,我把這個錯誤:Cpp Pantheios日誌庫,調試斷言失敗錯誤

Log Error

這裏是我的代碼:

Log.hpp

#ifndef INCLUDE_LOG_HPP 
#define INCLUDE_LOG_HPP 


#define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS // Faster compilation 

/* Pantheios Header Files */ 
#include <pantheios/pantheios.hpp>   // Pantheios C++ main header 
#include <pantheios/inserters/args.hpp>  // for pantheios::args 

#include <pantheios/backends/bec.file.h>  // be.file header 

#include "Include/utility.hpp" 
/* Standard C/C++ Header Files */ 
#include <exception>       // for std::exception 
#include <new>        // for std::bad_alloc 
#include <string>        // for std::string 
#include <stdlib.h>   
#include <sstream> 

#define PSTR(x)   PANTHEIOS_LITERAL_STRING(x) 


namespace Mtx 
{ 
    namespace log 
    { 
     class MTXMANAGER Logger 
     { 
     public: 
      void WriteLogIn(const std::string & log_text); 
      Logger(); 
      ~Logger(); 
     }; 
    } 
} 
#endif 

Log.cpp

#include "Log.hpp" 
namespace Mtx 
{ 
    namespace log 
    { 
     PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("mtx");// 
     Logger::Logger() 
     { 
      char path[MAX_PATH]; 
      GetModuleFileName(NULL, path, MAX_PATH); 

      std::string::size_type pos = std::string(path).find_last_of("\\"); 
      strcpy(path,std::string(path).substr(0, pos).c_str()); 
      std::strcat (path,"\\mtx-%D__.log"); 
      ///// 

      pantheios_be_file_setFilePath(PSTR(path), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_SHARE_ON_WINDOWS, PANTHEIOS_BEID_ALL); 

     } 

     Logger::~Logger() 
     { 

     } 

     void Logger::WriteLogIn(const std::string & log_text) 
     { 
      pantheios::log_INFORMATIONAL(PSTR(" [1] "),PSTR(log_text)); 
     } 

    } 
} 

我把錯誤這行:

pantheios::log_INFORMATIONAL(PSTR(" [1] "),PSTR(log_text)); 

我怎麼能解決這個錯誤?

回答

1

恐怕我沒有直接的答案給你,但是比較我在解決方案中的含義(這與你的設置很相似 - .NET DLL調用C++的原生DLL,它有Pantheios -logging),這裏是我有:

  • 我有一個項目日誌,其中有一個的InitInstance()和ExitInstance中()(和構建函數的CWinApp派生類 - CLogApp)
  • CLogApp構造函數/ dtor爲空
  • InitInstance()和ExitInstance()中的代碼:

    BOOL CLogApp::InitInstance() 
    { 
        CWinApp::InitInstance(); 
    
        int panres = pantheios::pantheios_init(); 
    
        if(panres < 0) 
        { 
         OutputDebugStringA("Could not initialise the Pantheios logging libraries!\n"); 
         util::onBailOut(pantheios::emergency, "Failed to initialise the Pantheios libraries", PANTHEIOS_FE_PROCESS_IDENTITY, /*pantheios::*/pantheios_getInitCodeString(panres)); 
    
         return FALSE; 
        } 
        else 
        { 
        pantheios_be_file_setFilePath(CErrorHandler::getLogPath().c_str(), PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BEID_LOCAL); 
    
        PANTHEIOS_TRACE_NOTICE("STARTING LOGGING"); 
        } 
    
        return TRUE; 
    } 
    
    int CLogApp::ExitInstance() 
    { 
        PANTHEIOS_TRACE_NOTICE("STOPPING LOGGING"); 
        pantheios_uninit(); 
        return 0; 
    } 
    

我不確定這是否會有所幫助,但此代碼已爲我工作了很多年了。