*《【WCE】使用事件日志服务(三 / 四)》的内容已重新调整过。
假设我们要记录一个事件源是 SQL Mobile 的事件到 Application 日志。需要如下步骤:
1. 使用菜单 Platform->Settings,在“Platform Settings”对话框中选择“Environment”标签,设置环境变量 SET PRJ_ENABLE_EVENTLOG = 1。
2. 在 project.reg 添加:
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/EventLog/Application]
"Output"="File"
"File"="ApplicationLog.xml"
"Format"="XML"
[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/EventLog/Application/SQL Mobile]
"EventMessageFile"="sqlce30ermsgs.dll"
3. 在 project.bib 添加:
MODULES
; Name Path Memory Type
; -------------- --------------------------------------------- -----------
sqlce30ermsgs.dll $(_FLATRELEASEDIR)/sqlce30ermsgs.dll NK SH
其中,sqlce30ermsgs.dll 是笔者编写的 SQLCE 3.0 的错误事件消息文件。
4. 执行 SYSGEN,生成新的操作系统映象,下载映象到模拟器。
5. 创建一个用于测试的 VC++ 2005 Win32 Smart Device Project,并命名为 reportevt:
{
HANDLE hEventLog(RegisterEventSource(NULL, TEXT("SQL Mobile")));
ReportEvent(hEventLog, EVENTLOG_ERROR_TYPE, 0, 0xC0000E00, NULL, 0, 0, NULL, NULL);
DeregisterEventSource(hEventLog);
return 0;
}
6. 使用刚才的模拟器调试 reportevt,可得调试输出信息:
4294768076 PID:43fc8c1a TID:43fc8bea 0x83fc8a3c: >>> Loading module eventlog.dll at address 0x03750000-0x0376B000 (RW data at 0x01F74000-0x01F748B4)
...
4294768116 PID:43fc8c1a TID:43fc8bea 0x83fc8a3c: EventLog:: EventLogInit() called
...
4294768746 PID:43fc8c1a TID:43fc8bea 0x83fc8a3c: EventLog:: EventLogStart(szDestinationFolder=/windows/) called
...
4294768896 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: EventLogWorkerThread() initiated
4294768896 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: System supports UTF8. EventLog will write log files in this format.
4294768906 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: Begin loading up format and outputter extensions
4294768936 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: Done loading up format and outputter extensions.
4294768946 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: About to initialize eventLogger for <System>
4294768966 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: Initialized file log /windows/SystemLog.xml, maxLog size = 32768
4294768976 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: EventLog <<System>> successfully initialized.
4294768976 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: About to initialize eventLogger for <Application>
4294768986 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: Initialized file log /windows/ApplicationLog.xml, maxLog size = 32768
4294768986 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: EventLog <<Application>> successfully initialized.
...
4294768996 PID:43fc8c1a TID:63fae7c2 0x83fca800: >>> Loading module eventlogmsgs.dll at address 0x03740000-0x03743000
...
4294769006 PID:43fc8c1a TID:63fae7c2 0x83fca800: EventLog: Printing out initial EventLog startup messages to EventLog log
...
268100 PID:3bf2a2e TID:3beae56 0x83bea800: >>> Loading module reportevt.exe at address 0x16010000-0x1602D000
...
268160 PID:3bf2a2e TID:3beae56 0x83bea800: InitSharedHeap: 44300000 0 c
268160 PID:3bf2a2e TID:3beae56 0x83bea800: InitSharedHeap: return 44300060
268210 PID:43fc8c1a TID:3beae56 0x83bea800: >>> Loading module sqlce30ermsgs.dll at address 0x01DF0000-0x01E04000
...
268330 PID:3bf2a2e TID:3beae56 0x83bea800: <<< Unloading module ole32.dll at address 0x03700000-0x03739000 (RW data at 0x01F70000-0x01F71520)
268340 PID:3bf2a2e TID:3beae56 0x83bea800: <<< Unloading module reportevt.exe at address 0x16010000-0x1602D000
...
268390 PID:3bf2a2e TID:3beae56 0x83bea800: <<< Unloading module coredll.dll at address 0x03F50000-0x03FF3000 (RW data at 0x01FFE000-0x01FFF765)
以及日志文件 ApplicationLog.xml:
<evt type="错误" d="2007-8-2" t="21:19:54" s="SQL Mobile" c="无" id="3221229056" msg="取值函数无效。[,,,,,]"/>