Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit a9533c6120.
PrevUpHomeNext

Class template basic_simple_event_log_backend

boost::log::sinks::basic_simple_event_log_backend — An implementation of a simple logging sink backend that emits events into Windows NT event log.

Synopsis

// In header: <boost/log/sinks/event_log_backend.hpp>

template<typename CharT> 
class basic_simple_event_log_backend :
  public basic_formatted_sink_backend< CharT, concurrent_feeding >
{
public:
  // types
  typedef base_type::char_type   char_type;               // Character type. 
  typedef base_type::string_type string_type;             // String type to be used as a message text holder. 
  typedef unspecified            event_type_mapper_type;  // Mapper type for the event type. 

  // construct/copy/destruct
  basic_simple_event_log_backend();
  template<typename... ArgsT> 
    explicit basic_simple_event_log_backend(ArgsT... const &);
  ~basic_simple_event_log_backend();

  // public member functions
  void set_event_type_mapper(event_type_mapper_type const &);
  void consume(record_view const &, string_type const &);

  // public static functions
  static string_type get_default_log_name();
  static string_type get_default_source_name();
};

Description

The sink uses Windows NT 5 (Windows 2000) and later event log API to emit events to an event log. The sink acts as an event source in terms of the API, it implements all needed resources and source registration in the Windows registry that is needed for the event delivery.

The backend performs message text formatting. The composed text is then passed as the first and only string parameter of the event. The resource embedded into the backend describes the event so that the parameter is inserted into the event description text, thus making it visible in the event log.

The backend allows to customize mapping of application severity levels to the native Windows event types. This allows to write portable code even if OS-specific sinks, such as this one, are used.

[Note] Note

Since the backend registers itself into Windows registry as the resource file that contains event description, it is important to keep the library binary in a stable place of the filesystem. Otherwise Windows might not be able to load event resources from the library and display events correctly.

[Note] Note

It is known that Windows is not able to find event resources in the application executable, which is linked against the static build of the library. Users are advised to use dynamic builds of the library to solve this problem.

basic_simple_event_log_backend public construct/copy/destruct

  1. basic_simple_event_log_backend();

    Default constructor. Registers event source with name based on the application executable file name in the Application log. If such a registration is already present, it is not overridden.

  2. template<typename... ArgsT> 
      explicit basic_simple_event_log_backend(ArgsT... const & args);

    Constructor. Registers event log source with the specified parameters. The following named parameters are supported:

    • target - Specifies an UNC path to the remote server which log records should be sent to. The local machine will be used to process log records, if not specified.

    • log_name - Specifies the log in which the source should be registered. The result of get_default_log_name is used, if the parameter is not specified.

    • log_source - Specifies the source name. The result of get_default_source_name is used, if the parameter is not specified.

    • registration - Specifies the event source registration mode in the Windows registry. Can have values of the registration_mode enum. Default value: on_demand.

    Parameters:

    args

    A set of named parameters.

  3. ~basic_simple_event_log_backend();

    Destructor. Unregisters event source. The log source description is not removed from the Windows registry.

basic_simple_event_log_backend public member functions

  1. void set_event_type_mapper(event_type_mapper_type const & mapper);

    The method installs the function object that maps application severity levels to WinAPI event types

  2. void consume(record_view const & rec, string_type const & formatted_message);

    The method puts the formatted message to the event log

basic_simple_event_log_backend public static functions

  1. static string_type get_default_log_name();

    Returns:

    Default log name: Application

  2. static string_type get_default_source_name();

    Returns:

    Default log source name that is based on the application executable file name and the sink name


PrevUpHomeNext