【发布时间】:2020-09-21 13:04:36
【问题描述】:
我正在运行由第三方提供的 dotnet 应用程序。事实上,有不止一个服务器组件包含几个web.config 文件和子web.config 文件。
我不想接触任何安装文件,以确保在以后的升级或其他阶段不会忘记任何配置更改。
我想启用通用日志记录,以便能够在 ysod 错误(例如损坏的配置文件)的情况下做出反应。我期望来自 java 世界,IIS 可能像 tomcat 一样将其未处理的异常写入一个简单的日志文件,但情况似乎并非如此。
最后我通过添加找到了solution
<healthMonitoring>
<eventMappings>
<add name="All Errors" type="System.Web.Management.WebBaseErrorEvent,System.Web,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647" />
</eventMappings>
<rules>
<add name="All Errors Default" eventName="All Errors" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom="" />
<add name="Failure Audits Default" eventName="Failure Audits" provider="EventLogProvider" profile="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom="" />
</rules>
</healthMonitoring>
到web.config-files 之一并强制应用程序在启动时失败并出现异常,现在我可以在事件监视器中看到错误,与 ysod 上的错误消息相比,这是一个很酷的进展配置
<!-- Web.Config Configuration File -->
(...)
<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</system.web>
</configuration>
(...)
但是,我想知道,我是否真的必须触摸web.config 文件才能启用非常基本的功能,例如注销未捕获异常的堆栈跟踪。
这感觉不对。
有没有办法以更通用的方式记录此类错误?
编辑在 Albert D. Kallal 的回答之后: 更准确地说:我不想接触应用程序的任何文件,我希望在比应用程序位置更高级别的通用配置。
【问题讨论】:
-
您是否在事件查看器中查看了 IIS 的错误日志?
-
我只能在事件查看器中找到 IIS-CentralCertificateProvider、IIS-Configuration 和 IIS-Logging。其中没有任何条目。你知道还有什么地方可以让我看看吗?
-
在事件查看器 -> Windows 日志 -> 应用程序中,您可以找到一些来自 iis 的日志。
-
不,从那里的应用程序中找不到任何有任何异常的日志。
-
您可以尝试在应用程序开始时设置此事件处理程序。在 Program.cs、Startup.cs 或您的 Global.asax 文件中。
AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) => { Debug.WriteLine(eventArgs.Exception.ToString()); };或打开位于 'C:\Windows\System32\inetsrv' 的 IIS 元数据库 检查 IIS 元数据库中的 AspErrorsToNTLog 并设置为 TRUE 并保存。docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/…