2

I have a cpp project, a cpp cli project and a c# win forms project. I use pantheios log library in my cpp native project. When i try to write log, i take this error :

Log Error

Here is my codes :

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));
        }  

    }
}

I take the error at this line :

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

How can i fix this error?

ali_bahoo
  • 4,732
  • 6
  • 41
  • 63
Seçkin Durgay
  • 2,758
  • 4
  • 27
  • 36

1 Answers1

1

I am afraid I don't have a direct answer for you, but comparing what I have in my solution (which is similar in many aspects with your setup - .NET DLL calling a C++-native DLL, which has Pantheios-logging), here is what I have:

  • I have a project LOG, which has an InitInstance() and ExitInstance() (and ctors for the CWinApp-derived class - CLogApp)
  • CLogApp ctor/dtor are empty
  • The code in InitInstance() and 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;
     }
    

I am not sure if this will help, but this code has been working for me for many years now.

ossandcad
  • 778
  • 5
  • 18