首页 > 解决方案 > 如何为 win32evtlogutil.ReportEvent() 正确定义 eventID

问题描述

我尝试通过下一个代码将日志保存到 Windows 日志中:

win32evtlogutil.ReportEvent(GnrwDaemon.APP_NAME,
                                        eventID=INFO_CODE_ID,
                                        eventType=win32evtlog.EVENTLOG_INFORMATION_TYPE,
                                        strings=n_data,
                                        data=b'TestApp',
                                        sid=my_sid)

哪里INFO_CODE_ID = 6146 # 0001 1000 0000 0010。我使用指令定义了这个 eventID - https://docs.microsoft.com/en-us/windows/win32/eventlog/event-identifiers

但是当我检查服务日志时,我得到了错误:

I can't find a description for the event ID 6146 from the TestApp source. The component that causes this event is not installed on this local computer or is corrupted. Install or restore the component on the local computer.

我在powershell中运行脚本如下: (python3 .\main.py install) -and (python .\main.py restart)

您能告诉我如何正确生成 eventID 以使 Windows 不会打印此错误吗?

除了这个问题,我也有一个。现在所有日志都被写入 Windows 日志(Журналы Windows),但我怎样才能将它们写入 Windows 的应用程序和服务日志(Журналы приложений и служб)(检查屏幕截图)?

在此处输入图像描述

标签: python-3.xwinapipywin32

解决方案


推荐阅读