简体   繁体   中英

Logging errors on Windows 2003 Server using the EventLog class

I've tried logging errors in my application, using the EventLog class.. But the Event Viewer on Windows 2003 Server is very limited as far as displaying the stuff I log.

Here's what I'm doing:

if (!EventLog.SourceExists("TestApp.exe"))
{
    EventLog.CreateEventSource("TestApp.exe", "TestApp");
}

EventLog.WriteEntry("TestApp.exe", Exception.Message);

The entry shows up in the Event Viewer, but I can't seem to find the the exception-message anywhere in the interface.

Am I doing something wrong? Or is the Event Viewer in Windows 2003 Server just crap? Are there any alternatives, beyond dumping errors to a text-file?

Two options are Systems.Diagnostics and log4net

Both can be configured to log to the file system, database, emails, eventlog, console, etc...

Log4net is my preferred option as I usually use NHibernate for data access.

Event properties should include needed information. You just have to double click event in the Event Viewer on 2003.

我最终将错误记录到文本文件中,因为Windows 2003中的事件查看器太简单了,无法显示我要记录的数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM