First step is download source code from github.

 
git clone https://github.com/jsternberg/log4cpp.git
 

If you are using Visual Studio 10, after update the solution file, modify log4cppLIB.vcxproj like this.

Locate Command element for Debug with Boost.

 
      <Command Condition="'$(Configuration)|$(Platform)'=='Debug with Boost|Win32'">if not exist "$(OutDir)" md "$(OutDir)"
mc.exe -h "$(ProjectDir)$(OutDir)." -r "$(ProjectDir)$(OutDir)." "$(ProjectDir)..\%(Filename).mc"
RC.exe -r -fo "$(OutDir)%(Filename).res" "$(OutDir)%(Filename).rc"
link.exe /MACHINE:IX86 -dll -noentry -out:"$(OutDir)NTEventLogAppender.dll" "$(OutDir)%(Filename).res"
</Command>
 
 
 

These double quotes makes the command line tools works properly.

Then modify PatternLayout.cpp, find "localtime" and replace it with

 
            //localtime(&t, ┬ĄtTime);
            localtime_s(┬ĄtTime,&t );
 
 

Now you can build log4cppLIB project, it will generate log4cpplibd.lib file.

Add the include directory to C++ include directory and add log4cpplibd.lib to Additional Dependencies.

Initial log4cpp with the code below.

 
 
 
// log4cpp
 
#include "log4cpp/Portability.hh"
#ifdef LOG4CPP_HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <iostream>
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#ifdef LOG4CPP_HAVE_SYSLOG
#include "log4cpp/SyslogAppender.hh"
#endif
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/SimpleLayout.hh"
#include "log4cpp/Priority.hh"
#include "log4cpp/NDC.hh"
log4cpp::Category * root = NULL;
 
 
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
 
    log4cpp::OstreamAppender* osAppender = new log4cpp::OstreamAppender("osAppender", &cout);
    osAppender->setLayout(new log4cpp::BasicLayout());
 
    log4cpp::Category & root1 = log4cpp::Category::getRoot();
    root = &root1;
 
    log4cpp::Appender *appender2 = new log4cpp::FileAppender("default", "log.txt");
 
    log4cpp::PatternLayout * layout = new log4cpp::PatternLayout();
    layout->setConversionPattern("%m");
    appender2->setLayout(layout);
 
 
    root->addAppender(appender2);
    root->setPriority(log4cpp::Priority::DEBUG);
 
    root->error("this is a error message!");
    root->warn("this is a warning message!");
    root->debug("this is a debug message");
    root->debug("this is %s, %d\n", "msg", 3);
 
    // using log4cpp
 
    log4cpp::Category::shutdown();
    return 0;
 
}