我想引发一个显示在 .NET 系统事件查看器 (eventvwr.exe) 中的“事件”。
不幸的是,Google 只是给了我很多关于“事件”的其他信息,这不是我想提出的那种事件。
什么是正确的 API 调用?
更新 感谢您到目前为止的回答。有趣的是,我发现即使我没有创建源,对“LogEvent”的调用也适用于新源。即
// The following works even though I haven't created "SomeNewSource"
EventLog.WriteEntry("SomeNewSource", message);
谁能解释一下这是为什么?
最佳答案
using System;
using System.Diagnostics;
namespace Test
{
class TestEventLog
{
static void Main(string[] args)
{
string source = "MyApplication";
if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source,"Application");
}
EventLog.WriteEntry(source, "Here is an event-log message");
}
}
}
关于c# - 如何在 .NET 中引发事件查看器 "Event"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1031581/