Generate Event Log in Cpp
The following code sample illustrates how to generate event logs.
Code Sample
See the C++ environment settings for details on setting the project environment.
<cpp_adminlog.cpp>
/*****************************************************************************************
*
* cpp_adminlog.cpp
*
*
******************************************************************************************/
#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin_local.h"
#include "teadmin_acl.h"
#include "teacl_template.h"
#include "tetemplateddirectory.h"
#include "teadmin_log.h"
#include "teeventlog.h"
using namespace ERUCES;
using namespace std;
int main()
{
string strServer = "xyang";
long nPort = 8888;
string strAdminUser = "admin";
string strAdminPswd = "password1A";
try
{
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection); // Use SecureConnection here
// Open connection to the server for native user
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strAdminUser);
ctx->setPasswd(strAdminPswd);
conn->open(strServer, nPort, *ctx.operator->());
cout << "Connected to " << strServer << " as " << strAdminUser << " at port " << nPort << endl;
TEAdminLog adminLog;
adminLog.attachConnection(conn.operator->());
TEEventLog eventLog;
eventLog.setData(0, 1);
eventLog.setData(1, 2);
eventLog.setData(2, 3);
eventLog.setData(3, 4);
eventLog.setData(0, "test 0");
eventLog.setData(1, "test 1");
eventLog.setData(2, "test 2");
eventLog.setData(3, "test 3");
adminLog.addEventLog(eventLog);
cout << "EventLog was added: " << endl;
// Disconnect from server
conn->close();
cout << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}
Output
Connected to xyang as admin at port 8888
EventLog was added:
Disconnected from xyang
Press any key to continue