ASMX Web 服务无法写入源应用程序错误日志 - EventLog 的访问被拒绝

发布于 2025-01-14 20:51:16 字数 661 浏览 3 评论 0 原文

我目前正在开发托管在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花海 2025-01-21 20:51:16

出现此问题的原因是,默认情况下,由于安全访问权限有限,应用程序的用户令牌不具备写入 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文