-
Notifications
You must be signed in to change notification settings - Fork 1
/
LogToEvViewer.h
150 lines (130 loc) · 4.53 KB
/
LogToEvViewer.h
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//---------------------------------------------------------------------------
#ifndef LogToEvViewerH
#define LogToEvViewerH
#include <Classes.hpp>
#include <System.SysUtils.hpp>
#include "Logbase.h"
#include "EventLogUtils.h"
#include "EvLogMessages.h"
//---------------------------------------------------------------------------
namespace SvcApp {
//---------------------------------------------------------------------------
namespace Log {
//---------------------------------------------------------------------------
template<typename T>
class LogToEvViewer : public FilteredLog<T> {
public:
explicit LogToEvViewer( String ServiceName );
template<typename F>
LogToEvViewer( F Filter, String ServiceName );
template<typename F>
LogToEvViewer( F Filter, String ServiceName, HINSTANCE ModuleInst );
protected:
virtual void DoAppend( const T& Item ) override;
private:
using Severity = typename T::SeverityType;
EventLog eventLog_;
static DWORD GetEvLogType( const T& Item );
static DWORD GetEvLogMessageId( const T& Item );
};
//---------------------------------------------------------------------------
template<typename T>
LogToEvViewer<T>::LogToEvViewer( String ServiceName )
: eventLog_( ServiceName )
{
}
//---------------------------------------------------------------------------
template<typename T>
template<typename F>
LogToEvViewer<T>::LogToEvViewer( F Filter, String ServiceName )
: FilteredLog<T>( Filter )
, eventLog_( ServiceName )
{
}
//---------------------------------------------------------------------------
template<typename T>
template<typename F>
LogToEvViewer<T>::LogToEvViewer( F Filter, String ServiceName, HINSTANCE ModuleInst )
: FilteredLog<T>( Filter )
, eventLog_( ServiceName, ModuleInst )
{
}
//---------------------------------------------------------------------------
template<typename T>
DWORD LogToEvViewer<T>::GetEvLogType( const T& Item )
{
switch( Item.GetSeverity() ) {
case Severity::Emergency: // system is unusable
return EVENTLOG_ERROR_TYPE;
case Severity::Alert: // action must be taken immediately
return EVENTLOG_WARNING_TYPE;
case Severity::Critical: // critical conditions
return EVENTLOG_ERROR_TYPE;
case Severity::Error: // error conditions
return EVENTLOG_ERROR_TYPE;
case Severity::Warning: // warning conditions
return EVENTLOG_WARNING_TYPE;
case Severity::Notice: // normal but significant condition
return EVENTLOG_SUCCESS;
case Severity::Informational: // informational messages
return EVENTLOG_INFORMATION_TYPE;
case Severity::Debug: // debug-level messages
return EVENTLOG_INFORMATION_TYPE;
default:
return EVENTLOG_SUCCESS;
}
}
//---------------------------------------------------------------------------
template<typename T>
DWORD LogToEvViewer<T>::GetEvLogMessageId( const T& Item )
{
switch( Item.GetSeverity() ) {
case Severity::Emergency: // system is unusable
case Severity::Alert: // action must be taken immediately
case Severity::Critical: // critical conditions
case Severity::Error: // error conditions
return MSG_ERROR;
case Severity::Warning: // warning conditions
return MSG_WARNING;
case Severity::Notice: // normal but significant condition
return MSG_SUCCESS;
case Severity::Informational: // informational messages
case Severity::Debug: // debug-level messages
return MSG_INFORMATIONAL;
default:
return MSG_SUCCESS;
}
}
//---------------------------------------------------------------------------
template<typename T>
void LogToEvViewer<T>::DoAppend( const T& Item )
{
// Logga solo il testo del messaggio...
// magari vedere se è il caso di aggiungere il resto delle
// informazioni presenti in T
/*
eventLog_.LogMessage(
GetEvLogType( Item ),
CAT_APP,
GetEvLogMessageId( Item ),
GetMessageText( Item ).c_str()
);
*/
String const Text = GetMessageText( Item );
String Ret = eventLog_.LogMessage(
GetEvLogType( Item ),
CAT_APP,
GetEvLogMessageId( Item ),
Text.c_str()
);
//#if defined( _DEBUG )
// ::OutputDebugString( Ret.c_str() );
//#endif
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
}; // End of namespace Log
//---------------------------------------------------------------------------
}; // End of namespace SvcApp
//---------------------------------------------------------------------------
#endif