サンプル9 testNTEventLog.cpp

 log4cpp::NTEventLogAppenderを使ったサンプルです。

※NTEventLogAppenderはWindowsのイベントログにログ出力を行うアペンダーです。

関連ファイル
  • testNTEventLog.cpp
ファイルの中身

testNTEventLog.cpp

  1. // testNTEventLog.cpp : Derived from testPattern.cpp.
  2. //
  3. #include "log4cpp/Portability.hh"
  4. #ifdef WIN32
  5. #include <windows.h>
  6. #endif
  7. #ifdef LOG4CPP_HAVE_UNISTD_H
  8. #include <unistd.h>
  9. #endif
  10. #include <stdlib.h>
  11. #include "log4cpp/Category.hh"
  12. #include "log4cpp/Appender.hh"
  13. #include "log4cpp/NTEventLogAppender.hh"
  14. #include "log4cpp/Priority.hh"
  15. int main(int argc, char* argv[])
  16. {
  17. log4cpp::Appender* appender =
  18. new log4cpp::NTEventLogAppender("default", "testNTEventLog");
  19. log4cpp::Category& sub1 =
  20. log4cpp::Category::getInstance(std::string("sub1"));
  21. sub1.addAppender(appender);
  22. sub1.setPriority(log4cpp::Priority::DEBUG);
  23. sub1.emerg("sub1 emerg");
  24. sub1.fatal("sub1 fatal");
  25. sub1.alert("sub1 alert");
  26. sub1.crit("sub1 crit");
  27. sub1.error("sub1 error");
  28. sub1.warn("sub1 warn");
  29. sub1.notice("sub1 notice");
  30. sub1.info("sub1 info");
  31. sub1.debug("sub1 debug");
  32. sub1.log(log4cpp::Priority::NOTSET, "sub1 notset");
  33. sub1.log(log4cpp::Priority::ERROR, "sub1 error");
  34. log4cpp::Category::shutdown();
  35. return 0;
  36. }

実行結果例

 testNTEventLog.cppをビルドし、実行した結果です。実行環境はWindows7(VC++2010 Express Edition)です。