提升事件记录器

时间:2016-03-11 15:54:18

标签: events logging boost

http://boost-log.sourceforge.net/libs/log/doc/html/log/detailed/sink_backends.html

在此页面中,有一些示例代码用于初始化boost窗口事件后端, 但是当我运行它时,它会在第一行产生内存错误。

void init_logging()
{
    // Create an event log sink
    boost::shared_ptr< sink_t > sink(new sink_t());

    sink->set_formatter
    (
        expr::format("%1%: [%2%] - %3%")
            % expr::attr< unsigned int >("LineID")
            % expr::attr< boost::posix_time::ptime >("TimeStamp")
            % expr::smessage
    );

    // We'll have to map our custom levels to the event log event types
    sinks::event_log::custom_event_type_mapping< severity_level > mapping("Severity");
    mapping[normal] = sinks::event_log::info;
    mapping[warning] = sinks::event_log::warning;
    mapping[error] = sinks::event_log::error;

    sink->locked_backend()->set_event_type_mapper(mapping);

    // Add the sink to the core
    logging::core::get()->add_sink(sink);
}

这里无法创建sink_t对象。

boost::shared_ptr< sink_t > sink(new sink_t());

知道问题是什么,我该如何解决?

另外如果你知道我可以使用提升事件记录学习任何其他来源,请写下来。

1 个答案:

答案 0 :(得分:1)

还没有回答......

但是我在Timo Geusch的博客中找到了解决方案。

http://www.lonecpluspluscoder.com/2011/01/boost-log-preventing-the-unhandled-exception-in-windows-7-when-attempting-to-log-to-the-event-log/

出现此问题的原因是应用程序需要访问两者的HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \ Services \ EventLog \中的注册表项必须存在(如果您不是管理员,则您没有权限创建它)并且运行应用程序的用户也需要能够读取和写入它。