我目前正在开发托管在 Windows Server 2016 上的 IIS 10 上的旧版 asp.net Web 服务 (asmx)。
在 IIS 中,Web 服务当前使用 Identity ApplicationPoolIdentity 运行。这是可以改变的。
我需要将消息记录到 Windows 事件查看器中,我使用“应用程序错误”作为事件源,因为它显然是 Windows 上已经存在的事件源。
因此,我参考 这篇文章 并使用以下 C# 代码:
try
{
System.Diagnostics.EventLog.WriteEntry("Application Error", "EventLog Test - Code EventLog", EventLogEntryType.Error);
}
catch (Exception ex)
{
// log error to file
}
当我运行应用程序时,我只收到以下错误日志:
< strong>无法打开源应用程序错误日志。您可能没有写入权限。
我可以在 IIS/registry/C# 中调整哪些设置来实现登录到我的 Windows 事件查看器?
你知道如何解决这个错误吗?
I'm currently working on a legacy asp.net webservice (asmx) hosted on an IIS 10 on Windows Server 2016.
In IIS the webservice is currently running with Identity ApplicationPoolIdentity. This can be changed.
I need to log Messages into the Windows Event Viewer, I use "Application Error" as the EventSource, as it apparently is an already existing event source on windows.
Therefore I refer to this post and use the following C# code:
try
{
System.Diagnostics.EventLog.WriteEntry("Application Error", "EventLog Test - Code EventLog", EventLogEntryType.Error);
}
catch (Exception ex)
{
// log error to file
}
When I run the application, I only get the following error log:
Unable to open log for source Application Error. You may not have write access.
Which settings could I adjust in IIS/registry/C# to achieve a log into my Windows Event Viewer?
Do you know how to solve this error?
发布评论
评论(1)
出现此问题的原因是,默认情况下,由于安全访问权限有限,应用程序的用户令牌不具备写入 Windows 事件日志所需的用户权限。
要为线程标识提供所需的权限,请通过服务器计算机上的以下注册表项修改事件日志的安全性。您应该选择应用程序正在写入的事件日志:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\Application\CustomSD
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\System\CustomSD
CustomSD 注册表值的类型为 REG_SZ,并包含采用安全描述符定义语言 (SDDL) 语法的安全描述符。
更多信息您可以参考此链接: https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/aspnet/development/fail-write-event-log#resolution。
This problem occurs because by default the user token of the application doesn't have the required user rights to write to the Windows event logs because of limited security access.
To provide the required permissions to the thread identity, modify the security of the event log through the below registry keys on the server machine. You should select the event log that your application is writing to:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\Application\CustomSD
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\System\CustomSD
The CustomSD registry value is of type REG_SZ and contains a security descriptor in Security Descriptor Definition Language (SDDL) syntax.
More information you can refer to this link: https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/aspnet/development/fail-write-event-log#resolution.