Show page source of Sample_testNTEventLog.cpp #80698

[[PageNavi(NavigationList)]]

==== サンプル9 testNTEventLog.cpp ====
 [http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1NTEventLogAppender.html log4cpp::NTEventLogAppender]を使ったサンプルです。

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

===== 関連ファイル =====
 * testNTEventLog.cpp 

===== ファイルの中身 =====
testNTEventLog.cpp [[BR]]
{{{ code cpp
// testNTEventLog.cpp : Derived from testPattern.cpp.
//

#include "log4cpp/Portability.hh"

#ifdef WIN32
#include <windows.h>
#endif
#ifdef LOG4CPP_HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <stdlib.h>

#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/NTEventLogAppender.hh"
#include "log4cpp/Priority.hh"

int main(int argc, char* argv[])
{
    log4cpp::Appender* appender = 
        new log4cpp::NTEventLogAppender("default", "testNTEventLog");

    log4cpp::Category& sub1 = 
        log4cpp::Category::getInstance(std::string("sub1"));
    sub1.addAppender(appender);
    sub1.setPriority(log4cpp::Priority::DEBUG);
    
    sub1.emerg("sub1 emerg");
    sub1.fatal("sub1 fatal");
    sub1.alert("sub1 alert");
    sub1.crit("sub1 crit");
    sub1.error("sub1 error");
    sub1.warn("sub1 warn");
    sub1.notice("sub1 notice");
    sub1.info("sub1 info");
    sub1.debug("sub1 debug");
    sub1.log(log4cpp::Priority::NOTSET, "sub1 notset");
    sub1.log(log4cpp::Priority::ERROR, "sub1 error");

    log4cpp::Category::shutdown();

    return 0;
}
}}}


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

[[Thumb(result.jpg, size=large , caption=イベントログ)]]

[[PageNavi(NavigationList)]]