admin
2023-02-09 125db633619a0b4c7bd1d498ea2bf1cefa4f73d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * NTEventLogAppender.hh
 *
 * See the COPYING file for the terms of usage and distribution.
 */
 
#ifndef _LOG4CPP_NTEVENTLOGAPPENDER_HH
#define _LOG4CPP_NTEVENTLOGAPPENDER_HH
 
#ifdef WIN32    // only available on Win32
 
// deal with ERROR #define
// N.B. This #includes windows.h with NOGDI and WIN32_LEAN_AND_MEAN #defined.
//      If this is not what the user wants, #include windows.h before this file.
#ifndef _WINDOWS_
#  ifndef NOGDI
#    define NOGDI  // this will circumvent the ERROR #define in windows.h
#    define LOG4CPP_UNDEFINE_NOGDI
#  endif
 
#  ifndef WIN32_LEAN_AND_MEAN
#    define WIN32_LEAN_AND_MEAN
#    define LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
#  endif
 
#  include <windows.h>
 
#  ifdef LOG4CPP_UNDEFINE_NOGDI
#    undef NOGDI
#  endif
 
#  ifdef LOG4CPP_UNDEFINE_WIN32_LEAN_AND_MEAN
#    undef WIN32_LEAN_AND_MEAN
#  endif
 
#endif // done dealing with ERROR #define
 
#include <log4cpp/Portability.hh>
#include <log4cpp/AppenderSkeleton.hh>
 
namespace log4cpp {
 
    /**
     * NTEventLogAppender is an Appender that sends LoggingEvents to the 
     * Windows event log.
     * Building log4cpp.dsp/log4cppDLL.dsp creates the resource DLL NTEventLogAppender.dll.
     * Do not forget to place this DLL in a directory that is on the PATH 
     * of the Windows system. Otherwise, the category and message will not display 
     * correctly in Event Viewer.<BR>
     * <B>NB:</B> This class is only available on Win32 platforms.
     **/
    class LOG4CPP_EXPORT NTEventLogAppender : public AppenderSkeleton {
    public:
 
        /**
         * Instantiate an NTEventLogAppender with given name and source.
         * @param name The name of the Appender
         * @param sourceName The source name to log
         **/         
        NTEventLogAppender(const std::string& name, const std::string& sourceName);
        virtual ~NTEventLogAppender();
 
        /**
         * Calls open() and close()
         **/
        virtual bool reopen();
 
        virtual void close();
 
        /**
         * The NTEventLogAppender does its own Layout.
         * @returns false
         **/
        virtual bool requiresLayout() const;
 
        virtual void setLayout(Layout* layout);
 
    protected:
        
        WORD getCategory(Priority::Value priority);
        WORD getType(Priority::Value priority);
        HKEY regGetKey(TCHAR *subkey, DWORD *disposition);
        void regSetString(HKEY hkey, TCHAR *name, TCHAR *value);
        void regSetDword(HKEY hkey, TCHAR *name, DWORD value);
        void addRegistryInfo(const char *source);
 
        virtual void open();
 
        /**
         * Sends a LoggingEvent to NT Event log.
         * @param event the LoggingEvent to log.
         **/
        virtual void _append(const LoggingEvent& event);
 
        HANDLE _hEventSource;
        std::string _strSourceName;
    };
}
 
#else // WIN32
#error NTEventLoggAppender is not available on on Win32 platforms
#endif    // WIN32
 
#endif // _LOG4CPP_NTEVENTLOGAPPENDER_HH