c# - 如何在 .NET 中引发事件查看器 "Event"?

标签 c# .net

我想引发一个显示在 .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/

相关文章:

c# - Unity - 如何旋转和全屏视频,在 RawImage 上使用 VideoPlayer API 播放

c# - 使用 XDT 转换的 Web.config 进行部分替换

c# - OleDbDataAdapter .Update 方法未保留架构更改

.net - 在不停止服务的情况下更新 dll

c# - 将 C# HashSet 转换为 F# 集

c# - 如何约束泛型类型必须有一个采用特定参数的构造函数?

c# - WPF中如何设置外边框、居中边框和内边框?

javascript - .Net Core 单选按钮总是返回 false

c# - 从非标准事件创建 Observable(无 EventArgs/EventHandler)

.net - 如果原始集合修改了 .NET,枚举器会发生什么情况