/* * Class: org_apache_log4j_nt_NTEventLogAppender * Method: reportEvent * Signature: (ILjava/lang/String;I)V */ JNIEXPORT void JNICALL Java_org_apache_log4j_nt_NTEventLogAppender_reportEvent( JNIEnv *env, jobject java_this, jint jhandle, jstring jstr, jint priority) { jboolean localHandle = JNI_FALSE; HANDLE handle = gEventSources.getHandle(jhandle); if (handle == 0) { // Client didn't give us a handle so make a local one. handle = RegisterEventSourceW(NULL, L"Log4j"); localHandle = JNI_TRUE; } // convert Java String to character array jsize msgLen = env->GetStringLength(jstr); jchar* msg = (jchar*) malloc((msgLen + 1) * sizeof(jchar)); env->GetStringRegion(jstr, 0, msgLen, msg); msg[msgLen] = 0; // This is the only message supported by the package. It is backed by // a message resource which consists of just '%1' which is replaced // by the string we just created. const DWORD messageID = 0x1000; ReportEventW(handle, getType(priority), getCategory(priority), messageID, NULL, 1, 0, (const wchar_t**) &msg, NULL); free((void *)msg); if (localHandle == JNI_TRUE) { // Created the handle here so free it here too. DeregisterEventSource(handle); } return; }
int wmain(int argc, wchar_t *argv[]) { if (argc < 3) { printf("usage: %ls <pid> (n_args args ...)+\n", argv[0]); return 0; } event_log = RegisterEventSourceW(NULL, PROVIDER_NAME); wait_for_parent(argv[1]); int arg_index = 2; while (arg_index < argc - 1) { unsigned long cmd_argc = wcstoul(argv[arg_index++], NULL, 10); if (cmd_argc == 0 || cmd_argc > argc - arg_index) { log_event(ERR_ARGS, "unexpected '%s' @ %d", argv[arg_index - 1], arg_index - 1); break; } else { wchar_t **cmd_argv = argv + arg_index; arg_index += cmd_argc; run_command((int)cmd_argc, cmd_argv, arg_index >= argc - 1); } } if (event_log != NULL) { DeregisterEventSource(event_log); } return 0; }
// // Purpose: // Logs messages to the event log // // Parameters: // szFunction - name of function that failed // // Return value: // None // // Remarks: // The service must have an entry in the Application event log. // VOID SvcReportEvent(LPTSTR szFunction) { HANDLE hEventSource; LPCWSTR lpszStrings[2]; WCHAR Buffer[80]; hEventSource = RegisterEventSourceW(NULL, SVCNAME); if( NULL != hEventSource ) { StringCchPrintfW(Buffer, 80, L"%s failed with %d", szFunction, GetLastError()); lpszStrings[0] = SVCNAME; lpszStrings[1] = Buffer; ReportEventW(hEventSource, // event log handle EVENTLOG_ERROR_TYPE, // event type 0, // event category EVENTLOG_ERROR_TYPE, // event identifier NULL, // no security identifier 2, // size of lpszStrings array 0, // no binary data lpszStrings, // array of strings NULL); // no binary data DeregisterEventSource(hEventSource); } }
/* * Class: org.apache.log4j.nt.NTEventLogAppender * Method: registerEventSource * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_apache_log4j_nt_NTEventLogAppender_registerEventSource( JNIEnv *env, jobject java_this, jstring server, jstring source) { jchar *nserver = 0; jchar *nsource = 0; if (server != 0) { jsize serverLen = env->GetStringLength(server); nserver = (jchar*) malloc((serverLen +1) * sizeof(jchar)); env->GetStringRegion(server, 0, serverLen, nserver); nserver[serverLen] = 0; } if (source != 0) { jsize sourceLen = env->GetStringLength(source); nsource = (jchar*) malloc((sourceLen +1) * sizeof(jchar)); env->GetStringRegion(source, 0, sourceLen, nsource); nsource[sourceLen] = 0; } addRegistryInfo((wchar_t*) nsource); jint handle = gEventSources.createKey(RegisterEventSourceW( (const wchar_t*) nserver, (const wchar_t*) nsource)); free(nserver); free(nsource); return handle; }
// // FUNCTION: CServiceBase::WriteEventLogEntry(PWSTR, WORD) // // PURPOSE: Log a message to the Application event log. // // PARAMETERS: // * pszMessage - string message to be logged. // * wType - the type of event to be logged. The parameter can be one of // the following values. // // EVENTLOG_SUCCESS // EVENTLOG_AUDIT_FAILURE // EVENTLOG_AUDIT_SUCCESS // EVENTLOG_ERROR_TYPE // EVENTLOG_INFORMATION_TYPE // EVENTLOG_WARNING_TYPE // void CServiceBase::WriteEventLogEntry(const wchar_t* pszMessage, WORD wType) { HANDLE hEventSource = NULL; LPCWSTR lpszStrings[2] = { NULL, NULL }; hEventSource = RegisterEventSourceW(NULL, m_name); if (hEventSource) { lpszStrings[0] = m_name; lpszStrings[1] = pszMessage; ReportEventW(hEventSource, // Event log handle wType, // Event type 0, // Event category 0, // Event identifier NULL, // No security identifier 2, // Size of lpszStrings array 0, // No binary data lpszStrings, // Array of strings NULL // No binary data ); DeregisterEventSource(hEventSource); } }
void log_info(wchar_t *mess){ HANDLE logh; wchar_t *strings[] = {service_name, mess , NULL}; if(!(logh = RegisterEventSourceW(NULL,APP_NAME))) return; ReportEventW(logh, EVENTLOG_INFORMATION_TYPE, 0, MSG_INFO, NULL, 2, 0, strings, NULL); DeregisterEventSource(logh); }
void EventLogChannel::open() { setUpRegistry(); #if defined(POCO_WIN32_UTF8) std::wstring uhost; UnicodeConverter::toUTF16(_host, uhost); std::wstring uname; UnicodeConverter::toUTF16(_name, uname); _h = RegisterEventSourceW(uhost.empty() ? NULL : uhost.c_str(), uname.c_str()); #else _h = RegisterEventSource(_host.empty() ? NULL : _host.c_str(), _name.c_str()); #endif if (!_h) throw SystemException("cannot register event source"); }
/****************************************************************************** * RegisterEventSourceA [ADVAPI32.@] * * Returns a registered handle to an event log. * * PARAMS * lpUNCServerName [I] UNC name of the source server. * lpSourceName [I] Specifies the name of the event source to retrieve. * * RETURNS * Success: Handle to the event log. * Failure: NULL. Returns ERROR_INVALID_HANDLE if lpSourceName specifies the * Security event log. */ HANDLE WINAPI RegisterEventSourceA( LPCSTR lpUNCServerName, LPCSTR lpSourceName ) { UNICODE_STRING lpUNCServerNameW; UNICODE_STRING lpSourceNameW; HANDLE ret; FIXME("(%s,%s): stub\n", debugstr_a(lpUNCServerName), debugstr_a(lpSourceName)); RtlCreateUnicodeStringFromAsciiz(&lpUNCServerNameW, lpUNCServerName); RtlCreateUnicodeStringFromAsciiz(&lpSourceNameW, lpSourceName); ret = RegisterEventSourceW(lpUNCServerNameW.Buffer,lpSourceNameW.Buffer); RtlFreeUnicodeString (&lpUNCServerNameW); RtlFreeUnicodeString (&lpSourceNameW); return ret; }
static gboolean gkrellmd_syslog_init() { #if defined(WIN32) h_event_log = RegisterEventSourceW(NULL, service_name); if (h_event_log == NULL) { g_warning("Cannot register event source for logging into Windows Event Log.\n"); return FALSE; } #else // Unix needs no logging initialization #endif return TRUE; }
DWORD logMessage(WORD wType, LPCWSTR message) { debug(L"Starting RegisterEventSourceW\n"); HANDLE hEventLog = RegisterEventSourceW(NULL, PROVIDER_NAME); LPCWSTR pInsertStrings[1] = {message}; DWORD dwEventDataSize = 0; if (hEventLog == NULL) return FALSE; debug(L"Starting ReportEventW\n"); if (!ReportEventW(hEventLog, wType, NULL, EVMSG_STDMSG, NULL, 1, 0, pInsertStrings, NULL)) { DeregisterEventSource(hEventLog); return FALSE; } DeregisterEventSource(hEventLog); return TRUE; }
static DWORD WINAPI service_stderr_thread(LPVOID hPipe) { HANDLE hPipeRead = (HANDLE) hPipe; HANDLE hEventSource; char errbuf[256]; char *errmsg = errbuf; const char *errarg[9]; DWORD errres; ap_regkey_t *regkey; apr_status_t rv; apr_pool_t *p; apr_pool_create_ex(&p, NULL, NULL, NULL); errarg[0] = "The Apache service named"; errarg[1] = display_name; errarg[2] = "reported the following error:\r\n>>>"; errarg[3] = errbuf; errarg[4] = NULL; errarg[5] = NULL; errarg[6] = NULL; errarg[7] = NULL; errarg[8] = NULL; /* What are we going to do in here, bail on the user? not. */ if ((rv = ap_regkey_open(®key, AP_REGKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\" "EventLog\\Application\\Apache Service", APR_READ | APR_WRITE | APR_CREATE, p)) == APR_SUCCESS) { DWORD dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; /* The stock message file */ ap_regkey_value_set(regkey, "EventMessageFile", "%SystemRoot%\\System32\\netmsg.dll", AP_REGKEY_EXPAND, p); ap_regkey_value_raw_set(regkey, "TypesSupported", &dwData, sizeof(dwData), REG_DWORD, p); ap_regkey_close(regkey); } hEventSource = RegisterEventSourceW(NULL, L"Apache Service"); SetEvent(stderr_ready); while (ReadFile(hPipeRead, errmsg, 1, &errres, NULL) && (errres == 1)) { if ((errmsg > errbuf) || !apr_isspace(*errmsg)) { ++errmsg; if ((*(errmsg - 1) == '\n') || (errmsg >= errbuf + sizeof(errbuf) - 1)) { while ((errmsg > errbuf) && apr_isspace(*(errmsg - 1))) { --errmsg; } *errmsg = '\0'; /* Generic message: '%1 %2 %3 %4 %5 %6 %7 %8 %9' * The event code in netmsg.dll is 3299 */ ReportEvent(hEventSource, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, 9, 0, errarg, NULL); errmsg = errbuf; } } } if ((errres = GetLastError()) != ERROR_BROKEN_PIPE) { apr_snprintf(errbuf, sizeof(errbuf), "Win32 error %lu reading stderr pipe stream\r\n", GetLastError()); ReportEvent(hEventSource, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, 9, 0, errarg, NULL); } CloseHandle(hPipeRead); DeregisterEventSource(hEventSource); CloseHandle(stderr_thread); stderr_thread = NULL; apr_pool_destroy(p); return 0; }
VOID InitLogs(VOID) { WCHAR szBuf[MAX_PATH] = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\ReactOS Application Manager\\ReactOS Application Manager"; WCHAR szPath[MAX_PATH]; DWORD dwCategoryNum = 1; DWORD dwDisp, dwData; HKEY hKey; if (!SettingsInfo.bLogEnabled) return; if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szBuf, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS) { return; } if (!GetCurrentDirectoryW(MAX_PATH, szPath)) return; wcscat(szPath, L"\\rapps.exe"); if (RegSetValueExW(hKey, L"EventMessageFile", 0, REG_EXPAND_SZ, (LPBYTE)szPath, (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS) { RegCloseKey(hKey); return; } dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; if (RegSetValueExW(hKey, L"TypesSupported", 0, REG_DWORD, (LPBYTE)&dwData, sizeof(DWORD)) != ERROR_SUCCESS) { RegCloseKey(hKey); return; } if (RegSetValueExW(hKey, L"CategoryMessageFile", 0, REG_EXPAND_SZ, (LPBYTE)szPath, (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS) { RegCloseKey(hKey); return; } if (RegSetValueExW(hKey, L"CategoryCount", 0, REG_DWORD, (LPBYTE)&dwCategoryNum, sizeof(DWORD)) != ERROR_SUCCESS) { RegCloseKey(hKey); return; } RegCloseKey(hKey); hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager"); }
void Logger::initLog(LPCWSTR name, DWORD logLevel) { if (!m_hEventSrc) m_hEventSrc = RegisterEventSourceW(NULL, name); if (!m_reportLogBuf) m_reportLogBuf = (WCHAR*)malloc(REPORT_LOG_BUF_SIZE); m_logLevel = logLevel; }