【发布时间】:2022-11-22 13:05:07
【问题描述】:
我有一个包含 3 个 Windows 服务的项目,这些服务运行良好,然后出于业务需要,我们需要从 Windows Server 2008 迁移到 Windows Server 2019。
我面临的问题是:
当我安装服务时,它没有启动并返回错误事件查看器:
无法启动服务。 System.Security.SecurityException: 未找到来源,但无法搜索到部分或所有事件日志。无法访问的日志:安全、状态。
我搜索了这个问题,找到了很多答案(比如this),但对我没有帮助。
我安装了服务管理员身份命令行使用安装工具.
然后打开了注册表编辑器并给用户网络服务完全控制路径如下:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog
然后我检查路径中服务的子项:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application而且,它存在。
我的代码与事件簿:
public class EventViewer { public static void WriteEvent(string ServiceName, string msg, EventLogEntryType _EventLogEntryType) { EventLog eventLog = new EventLog(); eventLog.Source = ServiceName; eventLog.Log = "Application"; ((System.ComponentModel.ISupportInitialize)(eventLog)).BeginInit(); if (!EventLog.SourceExists(eventLog.Source)) { EventLog.CreateEventSource(eventLog.Source, eventLog.Log); } ((System.ComponentModel.ISupportInitialize)(eventLog)).EndInit(); eventLog.WriteEntry(msg, _EventLogEntryType); } }这事件查看器给我异常行,它指的是:
((System.ComponentModel.ISupportInitialize)(eventLog)).BeginInit();我尝试使用调试我机器上的服务视觉工作室 2019,但也给我同样的错误,服务不会使用“附加到进程”开始调试。
【问题讨论】:
标签: exception windows-services event-log windows-server-2019