当尝试使用NTEventLogHandler记录某些内容时,我在"查看事件"中得到以下消息:
"在Source (Python Logging Test)中找不到事件ID(1)的描述。本地计算机可能没有必要的注册表信息或消息DLL文件来显示来自远程计算机的消息. ...">
Logger初始化如下:
def _create_windows_service_log(self):
if getattr(sys, 'frozen', False):
dllname = None
elif __file__:
dllname = os.path.dirname(__file__)
ntl = logging.handlers.NTEventLogHandler(self._app_name, dllname, self._app_name)
self._logger = logging.getLogger(self._app_name)
self._logger.setLevel(logging.INFO)
self._logger.addHandler(ntl)
它的用法如下:
self._logger.info(a_msg)
我检查了注册表中的数据。关键字EventMessageFile"指示文件"win32service.pyd"的正确路径。
我试着用那个方法,但是没有用。
关于dllname
参数的文档中提到:
dllname应该给出.dll或.exe的完全限定路径名,其中包含要保存在日志中的消息定义(如果未指定,则为'win32service. exe ')。pyd'被使用-这是与Win32扩展一起安装的,包含一些基本的占位符消息定义…)
我认为,如果在命名的DLL中没有找到消息id,你会得到这个问题。您似乎将dllname
传递为None
或目录的名称,这不能是DLL!