user5135280
user5135280

Reputation:

Boost event logger

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

In this page there is sample code to initialize boost windows event backends, but when I run it it gives memory error at first line.

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

Here it fails to create sink_t object.

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

Any idea what is the problem and how can I solve this?

Also If you know any other source that I can learn using boost event logging please write.

Upvotes: 1

Views: 560

Answers (1)

user5135280
user5135280

Reputation:

No answer yet...

But I have found a solution in a blog by 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/

The reason for this problem was that the registry key in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\ that the application needs access to both has to be present (if you’re not administrator, you don’t have the privileges to create it) and the user who runs the application also needs to be able to both read and write to it.

Upvotes: 1

Related Questions