默认情况下,ASP.NET 将所有未捕获的异常记录到系统事件日志中。我知道应该有一个适当的日志记录设施,但这总比没有好,而且它可以作为一种临时解决方案。
我希望能够有效地过滤日志中的事件。我了解到,以编程方式记录时,您可以通过以下方式为事件日志中的“源”列设置自定义值:
EventLog eventLog = new EventLog("Application");
eventLog.Source = "My custom name";
eventLog.WriteEntry("Some error description ...", EventLogEntryType.Error);
但是,ASP.NET 将此值设置为“ASP.NET”,后跟其版本。我简单地检查了 web.config 的文档,但没有找到明显的地方可以更改它。我想知道它是否可以改变。
最好的选择是按预期使用源属性,但在安装程序中使用安装程序类在安装时(在管理下)设置注册表,例如:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
namespace InstallerClasses
{
[RunInstaller(true)]
public partial class EventLog : Installer
{
private EventLogInstaller eventLogInstaller;
///
/// Creates the event log for MyApp
///
public EventLog()
{
InitializeComponent();
// Create an instance of an EventLogInstaller.
eventLogInstaller = new EventLogInstaller();
// Set the source name of the event log.
eventLogInstaller.Source = "MySource";
// Set the event log that the source writes entries to.
eventLogInstaller.Log = "Application";
// Add myEventLogInstaller to the Installer collection.
Installers.Add(eventLogInstaller);
}
}
}
并确保它在安装程序中作为自定义操作运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)