First step is download source code from github.

git clone

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"

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"
#include <unistd.h>
#include <iostream>
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#include "log4cpp/SyslogAppender.hh"
#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();
    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
    return 0;