Write to Windows event log: Difference between revisions

Line 282:
</pre>
Microsoft does provide an C/C++ API for EventCreate, but as with everything Microsoft, it's so wonderfully convoluted, that I will just give a link to the [https://msdn.microsoft.com/en-us/library/aa363680(v=vs.85).aspx ReportEvent] example.
 
=={{header|C++}}==
{{trans|C}}
<lang cpp>#include <iostream>
#include <sstream>
 
int main(int argc, char *argv[]) {
using namespace std;
 
#if _WIN32
if (argc != 5) {
cout << "Usage : " << argv[0] << " (type) (id) (source string) (description>)\n";
cout << " Valid types: SUCCESS, ERROR, WARNING, INFORMATION\n";
} else {
stringstream ss;
ss << "EventCreate /t " << argv[1] << " /id " << argv[2] << " /l APPLICATION /so " << argv[3] << " /d \"" << argv[4] << "\"";
system(ss.str().c_str());
}
#else
cout << "Not implemented for *nix, only windows.\n";
#endif
 
return 0;
}</lang>
 
=={{header|C sharp}}==
1,452

edits