Использование Boost Event Logger в приложении MFC: описание для идентификатора события не найдено

Я пытаюсь использовать библиотеку Boost Log для отправки событий в журнал событий Windows. Я сделал простое тестовое приложение C ++ для своего собственного регистратора, и все было хорошо.
Когда я использовал регистратор в приложении MFC, сгенерированные события, видимые в EventViewer, имеют эту ошибку

Описание для события с кодом 259 из источника MFCApplication1 не может
быть найденным….

Как я читаю в Повысить документацию basic_simple_event_log_backend «содержит все ресурсы, необходимые для правильной работы средства просмотра событий, и регистрирует библиотеку Boost.Log в реестре Windows, чтобы заполнить себя как контейнер этих ресурсов». но я думаю, что-то не получилось.

Есть идеи, как использовать его в приложении MFC? Я использую Boost 1.59 32bit и VS2013.

Для воспроизведения я сократил приложение MFC до одного файла cpp без каких-либо ресурсов:

#define VC_EXTRALEAN
#include <SDKDDKVer.h>
#define _AFX_ALL_WARNINGS
#include <afxwin.h>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_feature.hpp>
#include <boost/log/expressions/keyword.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/core.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/sink.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/event_log_backend.hpp>
#include <iomanip>

namespace logging
{
enum severity_level
{
fatal,
error,
warning,
info,
debug,
trace,
};

typedef boost::log::sources::severity_logger_mt<severity_level> dispatcher_type;
dispatcher_type disp;

BOOST_LOG_ATTRIBUTE_KEYWORD( severity, "Severity", severity_level)

void init( const std::string& appName)
{
namespace lg        = boost::log;
namespace src       = boost::log::sources;
namespace sinks     = boost::log::sinks;
namespace keyword   = boost::log::keywords;
namespace expr      = boost::log::expressions;
namespace attrs     = boost::log::attributes;

typedef sinks::synchronous_sink<sinks::simple_event_log_backend> evsink;
auto sink = boost::make_shared<evsink>( keyword::log_source = appName);
sink->set_formatter( expr::stream << expr::smessage);

sinks::event_log::custom_event_type_mapping<severity_level> mapping( severity.get_name());
mapping[ fatal]     = sinks::event_log::error;
mapping[ error]     = sinks::event_log::error;
mapping[ warning]   = sinks::event_log::warning;
mapping[ info]      = sinks::event_log::info;
mapping[ debug]     = sinks::event_log::info;
mapping[ trace]     = sinks::event_log::info;

sink->locked_backend()->set_event_type_mapper( mapping);
sink->set_filter( severity < info);
lg::core::get()->add_sink( sink);
}
}

#define LOG_ERROR BOOST_LOG_FUNCTION();BOOST_LOG_SEV(logging::disp, logging::error)

class CMFCApplication1App : public CWinApp
{
public:
const std::string appName = "MFCApplication1";

CMFCApplication1App()
{
if ( 0)
{
logging::init( appName);

LOG_ERROR << "hello1"; // // leads to a failed assert in
//>MFCApplication1.exe!boost::intrusive_ptr<boost::log::v2s_mt_nt5::attributes::named_scope::impl>::operator->() Line 174   C++
// MFCApplication1.exe!boost::log::v2s_mt_nt5::attributes::named_scope::push_scope(const boost::log::v2s_mt_nt5::attributes::named_scope_entry & entry) Line 289    C++
// MFCApplication1.exe!boost::log::v2s_mt_nt5::attributes::named_scope::sentry::sentry(const boost::log::v2s_mt_nt5::basic_string_literal<char,std::char_traits<char> > & sn, const boost::log::v2s_mt_nt5::basic_string_literal<char,std::char_traits<char> > & fn, unsigned int ln, boost::log::v2s_mt_nt5::attributes::named_scope_entry::scope_name_type t) Line 376    C++
// MFCApplication1.exe!CMFCApplication1App::CMFCApplication1App() Line 71   C++
// MFCApplication1.exe!`dynamic initializer for 'theApp''() Line 92 C++
}
}

virtual BOOL InitInstance()
{
if ( 1)
{
logging::init( appName);

LOG_ERROR << "hello2"; // leads to unknown event id
// The description for Event ID 259 from source MFCApplication1 cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
// If the event originated on another computer, the display information had to be saved with the event.
// The following information was included with the event:
// hello2
// The specified resource type cannot be found in the image file
}

return TRUE;
}

virtual int ExitInstance()
{
return CWinApp::ExitInstance();
}
};

CMFCApplication1App theApp;

1

Решение

Задача ещё не решена.

Другие решения


По вопросам рекламы ammmcru@yandex.ru
Adblock
detector