C++ 在MFC应用程序中使用Boost事件记录器:找不到事件ID的说明

C++ 在MFC应用程序中使用Boost事件记录器:找不到事件ID的说明,c++,logging,mfc,event-log,boost-log,C++,Logging,Mfc,Event Log,Boost Log,我正在尝试使用Boost日志库将事件发送到Windows事件日志。我为我的自定义记录器做了简单的C++测试应用,一切都很好。 当我在MFC应用程序中使用记录器时,EventViewer中可见的生成事件有此错误 无法从源MFCAPApplication1获取事件ID 259的描述 被发现 正如我在basic\u simple\u event\u log\u backend中读到的,“包含事件查看器正常运行所需的所有资源,并在Windows注册表中注册Boost.log库,以便将其自身填充为这些资源

我正在尝试使用Boost日志库将事件发送到Windows事件日志。我为我的自定义记录器做了简单的C++测试应用,一切都很好。 当我在MFC应用程序中使用记录器时,EventViewer中可见的生成事件有此错误

无法从源MFCAPApplication1获取事件ID 259的描述 被发现

正如我在basic\u simple\u event\u log\u backend中读到的,“包含事件查看器正常运行所需的所有资源,并在Windows注册表中注册Boost.log库,以便将其自身填充为这些资源的容器。”但我想可能是失败了

知道如何在MFC应用程序中使用它吗?我使用的是Boost 1.59 32位和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;
#定义VC#u超精益
#包括
#定义所有警告
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
名称空间日志记录
{
枚举严重性\u级别
{
致命的,
错误,
警告
信息,
调试,
跟踪,
};
typedef boost::log::sources::严重性\记录器\调度程序\类型;
调度器类型disp;
增强日志属性关键字(严重性,“严重性”,严重性级别)
void init(const std::string和appName)
{
名称空间lg=boost::log;
名称空间src=boost::log::sources;
名称空间sinks=boost::log::sinks;
名称空间关键字=boost::log::关键字;
名称空间expr=boost::log::expressions;
名称空间attrs=boost::log::attributes;
typedef sinks::同步_sink evsink;
自动接收=boost::使_共享(关键字::log_源=appName);
sink->set_格式化程序(expr::stream locked_backend()->set_event_type_mapper(映射);
接收器->设置过滤器(严重性<信息);
lg::core::get()->添加_接收器(接收器);
}
}
#定义LOG_ERROR BOOST_LOG_函数();BOOST_LOG_SEV(logging::disp,logging::ERROR)
CMFCApplication1App类:公共CWinApp
{
公众:
const std::string appName=“MFCAPApplication1”;
CMFCApplication1App()
{
如果(0)
{
日志:init(appName);
LogyMalfMFCpUpList1.xEX.Booo::BuffsiVIEWPTR::运算符->()174行C++
//MFCpUpLosi1.1.Exo.Boo::Log::V2sA.MTYNT5::属性::PosithSypCurst(const Booo::Log::V2sA.MTYNT5::属性:NAMEDIONEXCEL C++条目和条目)第289行C++
应用程序1.exe!Booo::log::No.Eng:NoTe::StIs::日志::V2SytMTYNT5::Basic StrgIn文字和SN,const Booost::日志:Basic StrugLyScript和FN,无符号int LN,Booo::日志::ValsSmithNoT5::SnopeEnMaEnEyt类型T)376 C++ //MFC.
//MFCpApultI1.exe!CMFCpAppultIAPAP::CMFCpAppult1App.()71行C++
//MFCpApdio1.1.exe!“TeApp’())92行C++的动态初始化程序
}
}
虚拟BOOL InitInstance()
{
如果(1)
{
日志:init(appName);
日志错误