1. Init regedit.
bool InitLog( TCHAR *logName, TCHAR *sourceName, TCHAR *MessageDllName )
    {
// This number of categories for the event source.
DWORD dwCategoryNum = ; HKEY hk;
DWORD dwData, dwDisp;
TCHAR szBuf[MAX_PATH];
size_t cchSize = MAX_PATH; // Create the event source as a subkey of the log. HRESULT hr = _stprintf_s(szBuf, //
_T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s"),
logName, sourceName); if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szBuf,
, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &hk, &dwDisp))
{
return false ;
} // Set the name of the message file. if (RegSetValueEx(hk, // subkey handle
_T("EventMessageFile"), // value name
, // must be zero
REG_EXPAND_SZ, // value type
(LPBYTE) MessageDllName, // pointer to value data
(DWORD) (lstrlen(MessageDllName)+)*sizeof(TCHAR))) // data size
{
RegCloseKey(hk);
return false ;
} // Set the supported event types. dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
EVENTLOG_INFORMATION_TYPE; if (RegSetValueEx(hk, // subkey handle
_T("TypesSupported"), // value name
, // must be zero
REG_DWORD, // value type
(LPBYTE) &dwData, // pointer to value data
sizeof(DWORD))) // length of value data
{
RegCloseKey(hk);
return false ;
} // Set the category message file and number of categories. if (RegSetValueEx(hk, // subkey handle
_T("CategoryMessageFile"), // value name
, // must be zero
REG_EXPAND_SZ, // value type
(LPBYTE) MessageDllName, // pointer to value data
(DWORD) (lstrlen(MessageDllName)+)*sizeof(TCHAR))) // data size
{
RegCloseKey(hk);
return false ;
} if (RegSetValueEx(hk, // subkey handle
_T("CategoryCount"), // value name
, // must be zero
REG_DWORD, // value type
(LPBYTE) &dwCategoryNum, // pointer to value data
sizeof(DWORD))) // length of value data
{
RegCloseKey(hk);
return false ;
} RegCloseKey(hk); //设置按需要覆盖重写日志
HKEY hKey; hr = _stprintf_s(szBuf, //
_T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s"),
logName); if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, NULL, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
DWORD dwRetentionNum = ;
if (RegSetValueEx(hKey, // subkey handle
_T("Retention"), // value name
, // must be zero
REG_DWORD, // value type
(LPBYTE) &dwRetentionNum, // pointer to value data
sizeof(DWORD))) // length of value data
{
RegCloseKey(hKey);
return false ;
}
}
RegCloseKey(hKey); _tcscpy_s ( m_SourceName, sourceName ) ; return true ;
}

2. Insert log

    void Log_Event ( DWORD dwEventId, WORD wType, TCHAR *pStr )
{
TCHAR* pBuf[1] ;
pBuf[0] = pStr ; if ( !m_bInit )
{
_tcscpy_s ( m_SourceName, _T("FAIL") ) ;
dwEventId = 0 ;
} HANDLE hEventSource = RegisterEventSource ( NULL, m_SourceName ) ;
if ( hEventSource != NULL )
{
ReportEvent ( hEventSource, // handle of event source
wType, // event type
0, // event category
dwEventId, // event ID
NULL, // current user's SID
1, // strings in lpszStrings
0, // no bytes of raw data
(LPCTSTR*)pBuf, // array of error strings
NULL ) ; // no raw data DeregisterEventSource ( hEventSource ) ;
}
} http://msdn.microsoft.com/en-us/library/aa363680(v=vs.85).aspx

Event log c++ sample.的更多相关文章

  1. ora-28056 (Writing audit records to Windows Event Log failed)

    系统:windows xp oracle 版本 SQL> select * from v$version; BANNER ------------------------------------ ...

  2. windows 系统无法启动windows event log 服务

    windows 系统无法启动windows event log 服务 关键词:无法启动系统事件日志 尝试解决步骤 [1]权限:把如图中logsfile文件等都给local service [2]把C: ...

  3. application pool can not write to event log

    https://stackoverflow.com/questions/9564420/the-source-was-not-found-but-some-or-all-event-logs-coul ...

  4. How to write to an event log by using Visual C#

    using System; using System.Diagnostics; namespace WriteToAnEventLog_csharp { /// Summary description ...

  5. AngularJS - $index, $event, $log

    原文: https://thinkster.io/egghead/index-event-log --------------------------------------------------- ...

  6. AWR发现TOP Event log file sequential read

    对客户DB进行巡检,发现TOP EVENT是LOG FILE Sequential read 等待事件说明 https://www.xuebuyuan.com/zh-hant/1743045.html ...

  7. KMS Event LOG

    The 12290 event entry gives a significant amount of information that can be used to figure out what ...

  8. 如何在 Windows Event Log 中查找系统重启的信息

    事件ID:12 事件ID 13: 事件ID 41: 事件ID 6008: 事件ID 1074:事件ID 1074: ========================================== ...

  9. Android 解读Event和Main Log

    1 Android P EventLogTags文件 Android P 9.0.0 所有EventLogTags文件List: system/bt/EventLogTags.logtags syst ...

随机推荐

  1. python3基础10(操作日志)

    #!/usr/bin/env python# -*- coding:UTF-8 -*- import logging, time, os # 这个是日志保存本地的路径log_path = " ...

  2. sql server 搭建发布订阅后,改端口不正常工作的问题

    sql 的发布订阅,想必大家都了解,但一般都是在默认的1433的情况下搭建的,那么1433换成别的端口,发布还能正常工作吗? 在一次客户的真实场景上我就遇到了. 好了,今天不想写太多,简化下, 测试环 ...

  3. jQuery_2_常规选择器-高级选择器2

    属性选择器 <a title="num1">num1</a> <a title="num-ad">num2</a> ...

  4. cms-数据库设计

    业务相关的3张表 1.类型表: CREATE TABLE `t_arctype` (`id` int(11) NOT NULL AUTO_INCREMENT,//id`typeName` varcha ...

  5. 避免使用 JS 特性 with(obj){}

    1)简要说明         with 语句可以方便地用来引用某个特定对象中已有的属性,但是不能用来给对象添加属性.要给对象创建新的属性,必须明确地引用该对象. 2)语法格式  with(object ...

  6. IOS NSBundle使用(访问文件夹)

    NSBundle的相关信息 1.一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2.利用mainBundle就可以访问软件资源包中的任何资源 3.模拟器应用程序的安装路径: ...

  7. 简析平衡树(三)——浅谈Splay

    前言 原本以为\(Treap\)已经很难了,学习了\(Splay\),我才知道,没有最难,只有更难.(强烈建议先去学一学\(Treap\)再来看这篇博客) 简介 \(Splay\)是平衡树中的一种,除 ...

  8. Oracle 函数 之 Coalesce()、greatest()、least()

    Coalesce().greatest().least() oracle比较一列的数据大小时,我们一般使用max()/min()函数,比较一行的最大值或者最小值时,使用函数Coalesce()/gre ...

  9. 第十三篇、OC_UICollectionView的基本配置

    - (UICollectionView *) categoryCollectionView { if (! _categoryCollectionView) { // 创建布局 UICollectio ...

  10. popen和pclose详解及实例

    popen函数是标准c提供的一个管道创建函数,其内部操作主 要是创建一个管道,调用fork创建子进程,关闭不需用的文件描述符,调用exec函数族执行popen的第一个参数.然后等到关闭. 也就是说我们 ...