bool log_event_log_message()

in src/Windows/dll/evtx_logging.cpp [105:145]


bool log_event_log_message(
    const std::string& a_msg,
    const WORD a_type)
{
    DWORD event_id;
    const std::string a_name(DCAP_DLL_NAME);
    bool success = false;

    switch (a_type)
    {
        case EVENTLOG_ERROR_TYPE:
            event_id = MSG_ERROR_1;
            break;
        case EVENTLOG_WARNING_TYPE:
            event_id = MSG_WARNING_1;
            break;
        case EVENTLOG_INFORMATION_TYPE:
            event_id = MSG_INFO_1;
            break;
        default:
            event_id = MSG_INFO_1;
            break;
    }

    HANDLE h_event_log = RegisterEventSourceA(0, a_name.c_str());

    if (h_event_log)
    {
        std::wstring a_w_msg(a_msg.begin(), a_msg.end());
        LPCWSTR message = a_w_msg.c_str();

        if (ReportEvent(h_event_log, a_type, 0, event_id, 0, 1, 0, &message, 0))
        {
            success = true;
        }

        DeregisterEventSource(h_event_log);
    }

    return success;
}