diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index fa9165f2..21325bf7 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -145,7 +145,7 @@ public: // get user token std::vector buffer(static_cast(tusize)); - if (!GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize, &tusize)) + if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize, &tusize)) { SPDLOG_THROW(win32_error("GetTokenInformation")); } @@ -207,9 +207,11 @@ private: { if (!hEventLog_) { - hEventLog_ = RegisterEventSource(nullptr, source_.c_str()); - if (!hEventLog_ || hEventLog_ == (HANDLE) ERROR_ACCESS_DENIED) + hEventLog_ = ::RegisterEventSource(nullptr, source_.c_str()); + if (!hEventLog_ || hEventLog_ == (HANDLE)ERROR_ACCESS_DENIED) + { SPDLOG_THROW(internal::win32_error("RegisterEventSource")); + } } return hEventLog_; @@ -225,7 +227,7 @@ protected: formatted.push_back('\0'); LPCSTR lp_str = static_cast(formatted.data()); - bool succeeded = ReportEvent( + auto succeeded = ::ReportEvent( event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), @@ -237,7 +239,9 @@ protected: nullptr); if (!succeeded) + { SPDLOG_THROW(win32_error("ReportEvent")); + } } void flush_() override {} diff --git a/tests/test_eventlog.cpp b/tests/test_eventlog.cpp index 4a3d3fce..114f2cb7 100644 --- a/tests/test_eventlog.cpp +++ b/tests/test_eventlog.cpp @@ -1,8 +1,8 @@ +#if _WIN32 + #include "includes.h" #include "test_sink.h" -#if _WIN32 - #include "spdlog/sinks/win_eventlog_sink.h" static const LPCSTR TEST_SOURCE = "spdlog_test"; @@ -66,4 +66,4 @@ TEST_CASE("eventlog", "[eventlog]") test_single_print([&test_logger] (std::string const& msg) { test_logger.critical(msg); }, "my critical message", EVENTLOG_ERROR_TYPE); } -#endif \ No newline at end of file +#endif //_WIN32 \ No newline at end of file