在事件日志源属性ASP.NET错误的自定义值 [英] Custom value for the Event Log source property for ASP.NET errors
问题描述
在默认情况下,ASP.NET记录所有未捕获的异常系统事件日志。我知道的一个事实,就是应该有一个适当的合适的日志记录功能,但是这总比没有好,它可以很好地充当一个临时解决方案。
By default, ASP.NET records all uncaught exceptions to system Event Log. I’m aware of the fact that one should have a proper logging facility in place, but this is better than nothing and it serves well as a temporary solution.
我想能够有效地过滤事件在日志中。我了解到,编程登录时,你可以通过在事件日志中源列设置自定义值:
I would like to be able to filter efficiently the events in the log. I learned that, when logging programmatically, you can set a custom value for the Source column in the event log via:
EventLog eventLog = new EventLog("Application");
eventLog.Source = "My custom name";
eventLog.WriteEntry("Some error description ...", EventLogEntryType.Error);
不过,ASP.NET将该值设置为ASP.NET,其次是它的版本。我简要地检查web.config中的文档,但是没有找到明显的地方去改变它。我不知道是否可以在一切都变了。
However, ASP.NET sets this value to "ASP.NET" followed by its version. I briefly checked the documentation of web.config, but did not find an obvious place to change it. I wonder if it can be changed at all.
推荐答案
您最好的选择是使用源属性如预期,但使用安装程序类在您的安装设置在安装时的注册表(管理下)例如:
Your best bet is to use the source property as intended, but use an installer class in your installer to set up the registry at install time (under Admin), eg.:
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);
}
}
}
和确定它在你的安装程序运行的自定义操作。
And make sure it gets run as a Custom Action in your installer.
这篇关于在事件日志源属性ASP.NET错误的自定义值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!