Windows事件日志 - 如何注册事件源? [英] Windows Event Log - how to register an event source?

查看:616
本文介绍了Windows事件日志 - 如何注册事件源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个新的事件源,并使用下面的code记录消息:

I am creating a new event source and logging a message using the code below:

    static void Main(string[] args)
    {
        if (!EventLog.SourceExists("My Log"))
        {
            EventLog.CreateEventSource("My Application", "My Log");
            Console.WriteLine("Created new log \"My Log\"");
        }

        EventLog myLog = new EventLog("My Log");
        myLog.Source = "My Application";
        myLog.WriteEntry("Could not connect", EventLogEntryType.Error, 1001, 1);
    }

自定义事件日志名为我的日志创建(如预期),但会记录该消息下方的应用程序节点。我究竟做错了什么?

A custom event log with the name "My Log" is created (as expected) but the message is logged below the "Application" node. What am I doing wrong?

推荐答案

有以下注意事项MSDN中:

There's the following note in MSDN:

如果源已经被映射到一个日志,你重新映射到一个新的日志,必须重新启动计算机使更改生效。

If a source has already been mapped to a log and you remap it to a new log, you must restart the computer for the changes to take effect.

是否有可能在试图走出code,你pviously尝试$ P $写入应用程序日志,您现在需要重新启动它以取消映射的链接?

Is it possible while trying out the code that you previously tried writing to the Application log and you now need to reboot for it to "unmap" that link?

这篇关于Windows事件日志 - 如何注册事件源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆